From string to double

A

Anonymous

Guest
--------------------------------------------------
I have the following field in the html form:

<INPUT TYPE=TEXT Name="car_supcup" Value="" style="width: 80pt">

where car_supcup must be a decimal value (say 12.56), but in Php $car_supcup is not equal to 12.56 but it's considered as 12!

Why? I need the decimal value (say 12.56) even if submitted in the html form as 12,56.

--------------------------------------------------
 
drimades said:
where car_supcup must be a decimal value (say 12.56), but in Php $car_supcup is not equal to 12.56 but it's considered as 12!

Why? I need the decimal value (say 12.56) even if submitted in the html form as 12,56.

PHP is what's called a dynamically-typed language. There's no way to make it distinguish between strings and numbers. If it looks like a number (e.g. "12.56"), PHP will be able to use it like a double. If your users use commas instead of periods for decimal points, it would serve you well just to change your locale settings, but if that's not an option, just use str_replace() to change all of the commas in the string to periods before you use it in a numerical context.
 
Back
Top