Page 1 of 1

How do you convert 10.00 to 1000?

Posted: Fri Jul 30, 2010 6:02 am
by simonmlewis
This may sound stupidly simple, but I cannot work it out.

I know you just times the figure by 100, but then I'd have 1000.00.
And I know how to 'printf' a value from that and set the 2 to 0, to show 1000.

Code: Select all

printf ("£%.2f", $value);
But how to you CONVERT it to the 1000 rather than just echo it?

Re: How do you convert 10.00 to 1000?

Posted: Fri Jul 30, 2010 6:12 am
by Weirdan

Code: Select all

$source = "10.00"; 
$converted = intval($source * 100); 
var_dump($converted);
intval is optional though, float(1000) is generally ok for all means and purposes.

Re: How do you convert 10.00 to 1000?

Posted: Fri Jul 30, 2010 6:20 am
by simonmlewis
Thanks.
so the result of this would be that $converted would render as 1000?

Re: How do you convert 10.00 to 1000?

Posted: Fri Jul 30, 2010 6:25 am
by Weirdan
simonmlewis wrote:Thanks.
so the result of this would be that $converted would render as 1000?
The results would be that $converted is integer variable, having a value of 1000. How it would be rendered depends on how you're rendering it.