FeralReason Posted May 16, 2009 Share Posted May 16, 2009 I am making an HTML form to edit an inventory record (retrieved from MySql). Does anyone know how I can format a float in a text field as currency. (Using PHP. Prefer not to use Javascript unless that is the only way.) Thanx ! Link to comment https://forums.phpfreaks.com/topic/158405-currency-format-in-form-text-field/ Share on other sites More sharing options...
gregor171 Posted May 16, 2009 Share Posted May 16, 2009 money_format ( string $format , float $number ); http://us2.php.net/money_format Link to comment https://forums.phpfreaks.com/topic/158405-currency-format-in-form-text-field/#findComment-835426 Share on other sites More sharing options...
FeralReason Posted May 16, 2009 Author Share Posted May 16, 2009 Thanks much for your quick reply. Unfortunately I am on a WAMP stack and money_format does not seem to be defined on Windows. Looked good tho.... Link to comment https://forums.phpfreaks.com/topic/158405-currency-format-in-form-text-field/#findComment-835497 Share on other sites More sharing options...
Ken2k7 Posted May 16, 2009 Share Posted May 16, 2009 What do you mean? It's a PHP function. Link to comment https://forums.phpfreaks.com/topic/158405-currency-format-in-form-text-field/#findComment-835504 Share on other sites More sharing options...
Axeia Posted May 16, 2009 Share Posted May 16, 2009 Note: The function money_format() is only defined if the system has strfmon capabilities. For example, Windows does not, so money_format() is undefined in Windows. Read the comments on the same page though, looks like someone posted a fully php based version of it doing the same thing for windows platforms. It does however not have a function check build in, so you might want to add that yourself unless you're sure your script will ALWAYS be run on a windows server since the 'native function' will doubtlessly be many times faster. Link to comment https://forums.phpfreaks.com/topic/158405-currency-format-in-form-text-field/#findComment-835516 Share on other sites More sharing options...
FeralReason Posted May 17, 2009 Author Share Posted May 17, 2009 Alexia - you are correct on both points. I did try this code and although it seems to correctly format the floating point value in the form's textbox I was then unable to edit / save the value -- so I am not sure that the money_format() function was intended to be used inside a form's text box. (If anyone is using this in a form, I would love to see how you are doing it !) I am fairly new to PHP/HTML but in other environments, setting how values are formatted (currency,etc) at the presentation layer (in forms) has always seemed fairly straightforward. I must be missing something... Link to comment https://forums.phpfreaks.com/topic/158405-currency-format-in-form-text-field/#findComment-836016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.