sprintf() to truncate and not round a float to x decimal places?
Posted
by jerrygarciuh
on Stack Overflow
See other posts from Stack Overflow
or by jerrygarciuh
Published on 2009-11-13T23:24:51Z
Indexed on
2010/05/26
21:21 UTC
Read the original article
Hit count: 494
Hi folks,
When calculating a golf handicap differential you are supposed to truncate the answer to 1 decimal place without rounding. No idea why but...
I know how to do this using TRUNCATE() in mySQL
SELECT TRUNCATE( 2.365, 1 );
// outputs 2.3
but I was wondering if sprintf() could do this? The only way I know to work with decimal places in a float is ...
echo sprintf("%.1f", 2.365);
// outputs 2.4
TIA
JG
© Stack Overflow or respective owner