Skip to content
Advertisement

Casting a value into FLOAT in PHP loses the decimal points. Basically turning the value into an INT

I’m calling a PHP form, the float value is received correctly, but if I cast it into a FLOAT, either immediately of afterwards, the value loses all decimal point numbers, and I don’t want that. I tried using floatval but same result.

JavaScript

Advertisement

Answer

Install proper locale settings on your machine. Probably you have installed IT (Italy) locale file and there is , as a decimal separator so casting doesn’t “see” that you pass it float number.

JavaScript

But it’s not sufficient to type this line into your code. You must also install locale file. More info: PHP setlocale has no effect

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement