# Tag: floating-point

## I changed my PHP MySQL statement to a prepared statement, and floats changed decimal point from period to comma

I have a MySQL table with floats in it. In PHPMyAdmin, they’re listed as e.g. “55.123” I used to pull them out using When I print my floats, I get e.g. “55.123” – hardly surprising. For obvious reasons I needed to change this query to a prepared statement: Now, when I print my float, I get e.g. “55,123” – with

## How to multiply small floats with unkown number of decimal places in PHP withouth getting zero because of scientific notation?

I’m trying to multiply some small numbers in PHP, but bcmul is returning zero because the float value is being turned into scientific notation. I tried using sprintf(‘%.32f’,\$value) on the small float …

## PHP Printf As Float Precision

I am attempting to use PHP’s printf function to print out a user’s storage capacity. The full formula looks something like this: Given that \$size == (10 * 1024 * 1024), this should print out 10.00 GB But it doesn’t. It prints 10.04 GB. Furthermore, results in 10.04 What?! In giving it an integer to convert to a float, it

## How can I make sure a float will always be rounded up with PHP?

I want to make sure a float in PHP is rounded up if any decimal is present, without worrying about mathematical rounding rules. This function would work as follows: 1.1 to 2 1.2 to 2 1.9 to 2 2.3 to …

## PHP unexpected result of float to int type cast

I’trying to convert a float to an int value in php: I can use ceil to make it work but can somebody explain this to me? Answer This is because numbers that have a finite representation in base 10 may or may not have an exact representation in the floating point representation PHP uses. See >php -r “echo var_dump(sprintf(‘%.40F’, 39.3