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 Link to comment https://forums.phpfreaks.com/topic/67957-force-a-number-to-have-2-decimals/ 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 Link to comment https://forums.phpfreaks.com/topic/67957-force-a-number-to-have-2-decimals/#findComment-341562 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. Link to comment https://forums.phpfreaks.com/topic/67957-force-a-number-to-have-2-decimals/#findComment-341608 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. Link to comment https://forums.phpfreaks.com/topic/67957-force-a-number-to-have-2-decimals/#findComment-341867 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/67957-force-a-number-to-have-2-decimals/#findComment-341914 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; } Link to comment https://forums.phpfreaks.com/topic/67957-force-a-number-to-have-2-decimals/#findComment-342159 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.