Hi! i had a problem a about calculating the numbers:
the instruction is to declare a variable with a value of 150000 and placed a number format.
so i used it like this:
$value1 = number_format (150000,2);
then, the value is first displayed:
i add the dollar sign from the first so that when i displayed it in the browser, the dollar sign appears.
printf ("$ $value1");
next thing is to calculate the value1 with a 10% increase:
i used this
$finalvalue = $c1 * 0.1 + $c1;
or this
$finalvalue = number_format ($c2 * 0.1 + $c2, 2);
then, when i saw it in the browser the value is wrong.
the calculation should be like this:
150000 * 0.1 + 150000 = 165000
but the instructions said that the output of it must be in the format like this:
$ 165,000.00
so what am i going to do? when i used that formula above, the calculation goes wrong like this:
$ 165.00
any help will be appreciated. thanks!
1 Replies  282 Views  Last Post: 30 January 2013  08:00 AM
#1
How to calculate a number that is used by the number format?
Posted 29 January 2013  08:48 PM
Replies To: How to calculate a number that is used by the number format?
#2
Re: How to calculate a number that is used by the number format?
Posted 30 January 2013  08:00 AM
first, printf() is not the same as print(). (though luckily printf() doesn’t throw an error here).
the calculation indicates that $c2 is 150, which is the value you get when trying to calculate with (the string) "150,000.00" (that gets parsed as a number and a comma is an invalid character for numbers, hence conversion stops at that point and returns all digits up to that point, which is 150).
besides that, the calculation is overly complicated. why not using the obvious y = x * 1.1 ?
the calculation indicates that $c2 is 150, which is the value you get when trying to calculate with (the string) "150,000.00" (that gets parsed as a number and a comma is an invalid character for numbers, hence conversion stops at that point and returns all digits up to that point, which is 150).
besides that, the calculation is overly complicated. why not using the obvious y = x * 1.1 ?
Page 1 of 1
