Jump to content

number_format question


speedy33417

Recommended Posts

I have a form update page where I grab some number values from a db and display it in this format 1,251.05 using this code:

 

input name="amount" value="<?php echo number_format ($amount, 2); ?>" class="form4">

 

 

How do reverse it though? If the form is submitted and the value (1,251.05) is saved in the db (float) it will actually save 1 and it cuts off the rest of the numbers after the comma.

 

Is there a function to make 1,251.05 into 1251.05?

I tried number_format ($amount, 2, '.', '') but it doesn't work. Probably because $amount at this point already has the comma in it.

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

  • 2 months later...

Please consider to wrap the str_replace() into a function for code reuse purposes.

 

function stripcomma($amount) {

  return str_replace(',', '', $amount);

}

 

Details see code example at: http://www.thewebscripter.com/tutorial/code_examples/number_format.php

 

Hope this helps.

 

Alex.

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.