Problem in displaying number format with comma and two decimal places
Good day!
I use round syntax in displaying my computation and the result is correct. but it has no comma.
Like for example the result is 3020, I want it to 3,020.00
I have this syntax:
PHP Code:
$Amount = round(($Hours/8)* $Rate, 2);
but when I tried number_format it displayed correct but I think the data or the amount is wrong because I sum amount in other earnings before i change the format, the output is 5524.28, but when I change my format of my amount the sum of other earnings and amount become 2507.88, so the data that get in amount is only 3.6.
i only want is adding comma, with changing the real amount or data.
If I'm reading that correctly, you cannot do math with numbers formatted that way (with comma separators). Only use the number_format() for outputting "pretty" results to the user.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
If I'm reading that correctly, you cannot do math with numbers formatted that way (with comma separators). Only use the number_format() for outputting "pretty" results to the user.
There is no reason I know of that you can't use number_format(). But any function you use that puts in thousands separators will create a string representation of a number. If you try to then use it as a number using PHP mathematical operators, it will cast that string to a numerical type, at which point things will go wrong. E.g. "123,456.78" would be cast to 123. The "trick" is to only use number format when you actually output something:
If that is not the issue, then we'll need to see some actual code to help you debug.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks