Jump to content

[SOLVED] Error in number format code?


lindm

Recommended Posts

I have a price of code that transforms a string as follows:

 

1. Removes blanks

2. Rounds the number

3. Adds blanks again

 

I get a strange output when trying to apply the code the negative numbers.

 

When a user for instance enters - 1 000 000 or -10 000 000 into the outcome is -100 000.

 

Code:

function rrab($string) {$string2 = str_replace(' ', '', $string); $string3 = round($string2); $string4 = number_format($string3, 0, ',', ' '); return $string4;}

 

 

Link to comment
https://forums.phpfreaks.com/topic/126141-solved-error-in-number-format-code/
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.