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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.