|
number_format duplicity
|
|
06-11-2012, 11:52 PM
(This post was last modified: 06-11-2012 11:53 PM by JiminSA.)
Post: #1
|
|||
|
|||
|
number_format duplicity
I'm using number_format as opposed to sprintf to format 2 fields to be comma delimited, like so...
PHP Code: $vehicles["vehicles"][$vehicles["nextid"]] = array( "make" => $_REQUEST["make"], "model" => $_REQUEST["model"], "year" => (int)$_REQUEST["year"], "price" => number_format(($_REQUEST["price"]), 2), "Kms" => number_format(($_REQUEST["Kms"]), 0), "doors" => $_REQUEST["doors"], as you can see one has 2 decimal places and the other does not. Problem: When I edit the price field the Kms field is reformatted! (i.e. any comma is treated as a decimal point - so that a value of 155,000 becomes 155) Conversely... When I edit the Kms field the price field is reformatted! (i.e. any comma is treated as a decimal point - so that a value of 68,700.00 becomes 68.00) If I edit both fields before form submission it formats both correctly Here is the generated html... Code: </td><td> <div class="formitem">If you don't squeak, you won't get oiled!
|
|||
|
06-12-2012, 10:58 PM
Post: #2
|
|||
|
|||
|
RE: number_format duplicity
You need to remove the comma before feeding it into number_format(). It needs to be a numeric value. It is best to store a numeric value too. IMO, the admin doesn't matter how the number gets displayed - only the frontend really matters.
Author of Barebones CMS If you found my reply to be helpful, be sure to donate! All funding goes toward future product development. |
|||
|
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)

Search
Help




