How do you convert 10.00 to 1000?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

How do you convert 10.00 to 1000?

Post 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?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: How do you convert 10.00 to 1000?

Post 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.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do you convert 10.00 to 1000?

Post by simonmlewis »

Thanks.
so the result of this would be that $converted would render as 1000?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: How do you convert 10.00 to 1000?

Post 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.
Post Reply