[SOLVED]moving the point(.) in a number

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
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

[SOLVED]moving the point(.) in a number

Post by pelegk2 »

i want to take any number between
1.999 withought knowing in advance
its value
and to make it 0.something
(which means to move the dot to the lfet until the first time i get 0. )
for example
947->0.947
43->0.43
and so on
how can i do that>?
thnaks i nadvance
peelg
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

You could use a loop:

Code: Select all

$a = 947; //or whatever
while ($a > 0.99999999)
{
    $a /= 10;
}
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Nah, don't mention it ;)
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

Or you could just do:

Code: Select all

$value = 947;
$new_value = '0.' . $value;
;) gotta love auto-type conversion!
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

thanks alot both of u:)
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

:lol: LMAO at Launchcode's suggestion.

/smack head on desk

Just (bonk) add (bonk) a (bonk) zero (bonk) and (bonk) a (bonk) point (bonk) to (bonk) the (bonk) string (bonk)!
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

:D
Post Reply