Forum Moderators: coopster

Message Too Old, No Replies

Decimal Variable

How to verify its a decimal and if not, turns it into a decimal

         

wfernley

3:48 pm on Aug 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi everyone.

I was curious on how to see if a variable has 2 decimal points and then if it doesn't convert it to a decimal value.

For example, if I have a value that is 5700, I need to convert it to 5700.00.

Thanks for your help :)

Wes

jatar_k

4:09 pm on Aug 4, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what about
number_format [ca3.php.net]?

wfernley

1:05 pm on Aug 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks jatar_k!

I looked up that function and found that sprintf would work great.

I then did this:

$total = sprintf("%01.2f",$total);

It works great and converts it to the format I need.

Thanks again :)