Jump to content

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.

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.