# How to calculate a number that is used by the number format?

Page 1 of 1

## 1 Replies - 419 Views - Last Post: 30 January 2013 - 08:00 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=310226&amp;s=7add437c0d8079d80300d846503e5fbe&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 brerallia

Reputation: 0
• Posts: 149
• Joined: 21-January 13

# How to calculate a number that is used by the number format?

Posted 29 January 2013 - 08:48 PM

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!

Is This A Good Question/Topic? 0

## Replies To: How to calculate a number that is used by the number format?

### #2 Dormilich

• 痛覚残留

Reputation: 3739
• Posts: 11,297
• Joined: 08-June 10

## 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 ?