JustinK101 Posted October 31, 2006 Share Posted October 31, 2006 How do I set precision of a number?So instead of returning 128 I want it to always display two places after the decimal point, so: 128.00.Thanks. Link to comment https://forums.phpfreaks.com/topic/25756-setting-number-precision/ Share on other sites More sharing options...
Barand Posted October 31, 2006 Share Posted October 31, 2006 $x = 128;echo number_format ($x, 2);printf ('%08.2f', $x); Link to comment https://forums.phpfreaks.com/topic/25756-setting-number-precision/#findComment-117595 Share on other sites More sharing options...
the_oliver Posted October 31, 2006 Share Posted October 31, 2006 Is this returning from a calculation or a database? If database its best to do this at time of insertion buy having your submision insist on it. Alternitivly some database can do this server side.Perhaps if its returning it from a calculation on the page it could be achived by multiplying it by '1.00' as this won't change the figure? Not sure about this one though. Link to comment https://forums.phpfreaks.com/topic/25756-setting-number-precision/#findComment-117597 Share on other sites More sharing options...
JustinK101 Posted November 1, 2006 Author Share Posted November 1, 2006 number_format() did the trick. Thanks Barand, you seem to answer all my questions. :) LOL Link to comment https://forums.phpfreaks.com/topic/25756-setting-number-precision/#findComment-117614 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.