Hartley Posted September 4, 2007 Share Posted September 4, 2007 I have a query, and one of the results is a number that I want to forcefully have rounded to 2 decimal places. I couldn't find a good search query to find this if it's been asked before How can I achieve it, so it's like 1.00 or 187.25 Quote Link to comment Share on other sites More sharing options...
lemmin Posted September 4, 2007 Share Posted September 4, 2007 Try this: http://us.php.net/manual/en/function.number-format.php Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 4, 2007 Share Posted September 4, 2007 Uhm, not to be rude but you couldn't find this in search? A search for decimals turned up a few related posts. Quote Link to comment Share on other sites More sharing options...
tippy_102 Posted September 5, 2007 Share Posted September 5, 2007 Google "php dollar format", then click on "I'm feeling lucky" function dollar_format($amount) { $new_amount = "\$".sprintf("%.2f",$amount); return $new_amount; } That will work. Quote Link to comment Share on other sites More sharing options...
jitesh Posted September 5, 2007 Share Posted September 5, 2007 <?php $value = 19.11; if(preg_match("/^\d{1,3}(,?\d{3})*(\.\d{2})?$/",$value)){ echo "Right"; }else{ echo "Wrong"; } ?> Quote Link to comment Share on other sites More sharing options...
cordoprod Posted September 5, 2007 Share Posted September 5, 2007 function force_to_decimals($number) { $a = explode(",", $number); $result = false; if(strlen($a[1] == 2) { $result = true; } else $result = false; return $result; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.