View Full Version : If there's only one number after the decimal place in a value - add a 0 after it.
Link14716
02-06-2004, 08:36 PM
How would I go about pulling something like this off?
g-force2k2
02-06-2004, 09:20 PM
try the round function.
$newnumber = round ( $number, 2 ) ;
Cheers,
g-force2k2
Link14716
02-06-2004, 09:22 PM
The number is already rounded to two decimal places before being store in the database. I'll try using round again before it is displayed, I don't think it'd work though.
EDIT: No dice.
g-force2k2
02-06-2004, 09:25 PM
It could perhaps be the column field type that's causing the problem.
Cheers,
g-force2k2
Link14716
02-06-2004, 09:27 PM
It could perhaps be the column field type that's causing the problem.
Cheers,
g-force2k2
Well, it doesn't work when I try it before displaying the number.
The column type is varchar.
g-force2k2
02-06-2004, 09:41 PM
There could perhaps be an easier way then I know of, but instead I just made a quick fucntion:
function twopl_round ( $number )
{
$numbits = explode ( ".", $number ) ;
if ( strlen ( $numbits[1] ) < 2 ) :
$number.= '0' ;
endif ;
return $number ;
}
Just call the function by:
$number = twopl_round ( $number ) ;
Cheers,
g-force2k2
Link14716
02-06-2004, 09:47 PM
Works like a charm! Thanks, g-force!
g-force2k2
02-06-2004, 09:49 PM
Works like a charm! Thanks, g-force!
Hey no problem, glad it worked :)
Cheers,
g-force2k2
Xenon
02-06-2004, 11:30 PM
i know you've got the way you want it already, but i may say, there is already a function in php which does that afaik
$number = number_format($number, 2, '.', '');
Link14716
02-06-2004, 11:41 PM
That shows how much I use number_format :p
Thank you, Xenon and g-force2k2 for the help. :)
Xenon
02-07-2004, 12:00 AM
hehe, i don't use it as well normally, but i knew the name and thought it must have a function, or it wouldn't be in the php function list ;)
glad i could help
g-force2k2
02-07-2004, 12:59 AM
i know you've got the way you want it already, but i may say, there is already a function in php which does that afaik
$number = number_format($number, 2, '.', '');
haha, thanks for the tip Xenon, I'll have to remember this function for future use, I knew vbulletin uses this function in it's script just didn't really think of it. Thanks for the heads up though :)
Cheers,
g-force2k2
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.