newphpcoder Posted March 20, 2012 Share Posted March 20, 2012 Hi.. I used this code for displaying formatted number and I notice that instead comma(,) it become point(.): $P28_maxdoz = $row['P28_maxdoz']; $P28_maxdoz = number_format($P28_maxdoz, 2, '.', ','); <table> <tr> <td><input type='text' name='P28_maxdoz' value="<?php echo $P28_maxdoz;?>"></td> </tr> </table> the output is : 22.782.20 i need output is : 22,782.20 Thank you Quote Link to comment https://forums.phpfreaks.com/topic/259308-number_format-inside/ Share on other sites More sharing options...
Psycho Posted March 20, 2012 Share Posted March 20, 2012 Hmm, are you sure the value from the database is a number to begin with? Try the following and post what you get: $P28_maxdoz = number_format($row['P28_maxdoz'], 2, '.', ','); echo "Value from DB: " . var_dump($row['P28_maxdoz']); echo "<br>Value after format: " . var_dump($P28_maxdoz); Quote Link to comment https://forums.phpfreaks.com/topic/259308-number_format-inside/#findComment-1329276 Share on other sites More sharing options...
newphpcoder Posted March 20, 2012 Author Share Posted March 20, 2012 this is the output: string( "22782.20" Value from DB: string( "22782.20" Value after format: Thankyou Quote Link to comment https://forums.phpfreaks.com/topic/259308-number_format-inside/#findComment-1329312 Share on other sites More sharing options...
Psycho Posted March 20, 2012 Share Posted March 20, 2012 this is the output: string( "22782.20" Value from DB: string( "22782.20" Value after format: Thankyou Next time, put the output in [ code ] tags so it isn't modified into smilies . Anyway, something doesn't seem right. The value from the DB is "22782.20" and after formatting with number_format() it is unchanged. I just rant the same test with hard-coding the same value to test with - I even forced the value to be a string: $row['P28_maxdoz'] = (string) "22782.20"; $P28_maxdoz = number_format($row['P28_maxdoz'], 2, '.', ','); echo "Value from DB: "; var_dump($row['P28_maxdoz']); echo "<br>Value after format: "; var_dump($P28_maxdoz); My output: Value from DB: string( "22782.20" Value after format: string(9) "22,782.20" Even if your server had a non-US localization set, the 3rd and 4th parameters of number_format() should have overridden the defaults. Quote Link to comment https://forums.phpfreaks.com/topic/259308-number_format-inside/#findComment-1329449 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.