Jump to content

Divide?


moiisam10

Recommended Posts

Hello guys... Am here again maybe with a noob question.. but well am just triying to learn all possible.

I got a variable...

$lal = 4820.492

and i need to divie all in 2... like

$lal2 = 2410.246

I triyied with

$lal2 = $lal/2;
echo $lal2;

But i just get the first character. so its "2" , i triyed with explode but dont work or dont know, with number_format and i dont know how to make it work.. Thanks in advanced to all. 

Link to comment
https://forums.phpfreaks.com/topic/297836-divide/
Share on other sites

Oh. This is from yesterday?

 

You cannot do math operations with numbers which are formatted. You need to remove the number formatting so its whole number

// remove number formatting
$lal = str_replace(',', '', $row[0]->nodeValue);

// now divide by 2
$lal2 = floatval($lal) / 2;
echo $lal2;

If you dont remove the formatting PHP will truncate the value before the comma, so only 4 will be divided by 2 this why the result is 2

Link to comment
https://forums.phpfreaks.com/topic/297836-divide/#findComment-1519114
Share on other sites

Oh. This is from yesterday?

 

You cannot do math operations with numbers which are formatted. You need to remove the number formatting so its whole number

// remove number formatting
$lal = str_replace(',', '', $row[0]->nodeValue);

// now divide by 2
$lal2 = floatval($lal) / 2;
echo $lal2;

If you dont remove the formatting PHP will truncate the value before the comma, so only 4 will be divided by 2 this why the result is 2

Thanks again bro , i look like a real noob.. 

Link to comment
https://forums.phpfreaks.com/topic/297836-divide/#findComment-1519115
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.