Home
Site map
Contact
Categories
PHP design patterns
PHP code samples
J2EE with JBoss and Eclipse Survival Log
Learning Drupal
Learn Symfony
Javascript
Java
Linux Survival
Download
Articles
See How: a simple CMS
Free Delta
PHP code samples
Truncate decimals without rounding
Truncate decimals without rounding
To truncate a number to two decimal places without rounding. Try this:
((int)($myNumber*100)/100)
Using the
int
casting
//-- Try with: 29.99568
$myNumber=29.99568;
echo ((int)($myNumber*100)/100) ;
//-- It prints out: 29.99
Date: June 20, 2009
Search in this site
Subscribe to my RSS FEED: