Jump to content

number_format inside <input type = "text">


newphpcoder

Recommended Posts

 

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

Link to comment
https://forums.phpfreaks.com/topic/259308-number_format-inside/
Share on other sites

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);  

this is the output:

 

string(8) "22782.20" Value from DB: string(8) "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.

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.