Top "Floating-point" questions

Floating point numbers are approximations of real numbers that can represent larger ranges than integers but use the same amount of memory, at the cost of lower precision.

C++: How to round a double to an int?

I have a double (call it x), meant to be 55 but in actuality stored as 54.999999999999943157 which I just realised. So …

c++ floating-point rounding
round() for float in C++

I need a simple floating point rounding function, thus: double round(double); round(0.1) = 0 round(-0.1) = 0 round(-0.9) = -1 I can …

c++ floating-point rounding
PHP String to Float

I am not familiar with PHP at all and had a quick question. I have 2 variables pricePerUnit and InvoicedUnits. Here's …

php string casting floating-point
JavaScript displaying a float to 2 decimal places

I wanted to display a number to 2 decimal places. I thought I could use toPrecision(2) in JavaScript . However, if the …

javascript floating-point precision
Python float to int conversion

Basically, I'm converting a float to an int, but I don't always have the expected value. Here's the code I'm …

python floating-point int
Format Float to n decimal places

I need to format a float to "n"decimal places. was trying to BigDecimal, but the return value is not …

java android floating-point numbers format
Round a Floating Point Number Down to the Nearest Integer?

As the title suggests, I want to take a floating point number and round it down to the nearest integer. …

python floating-point integer rounding
How do you round a floating point number in Perl?

How can I round a decimal number (floating point) to the nearest integer? e.g. 1.2 = 1 1.7 = 2

perl floating-point rounding
Is floating point math broken?

Consider the following code: 0.1 + 0.2 == 0.3 -> false 0.1 + 0.2 -> 0.30000000000000004 Why do these inaccuracies happen?

math language-agnostic floating-point floating-accuracy
Display a float with two decimal places in Python

I have a function taking float arguments (generally integers or decimals with one significant digit), and I need to output …

python string floating-point