I
I
IdFox2018-03-30 05:16:54
PHP
IdFox, 2018-03-30 05:16:54

How to round a number to significant digits?

How to round a number to significant digits?
I don’t quite understand why, but numbers are stored in the database (type double)
And PHP (MySQL?) Extracts some (not all) incorrectly
For example, there is a number in the database - 69.6
It is extracted as 69.59999999999999
Or the number 8.3
is Extracted as 8.30000000001
Where do these insignificant numbers?
Is it some kind of setting in PHP or MySQL?
How can you normalize numbers?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sanovskiy, 2018-03-30
@IdFox

SQL floating point comparison issues

SELECT ROUND(8.30000000001,2);
-- 8.30

$a = round(8.30000000001,2);
// 8.30

R
Rsa97, 2018-03-30
@Rsa97

In general, change the data type to DECIMAL .
In private, for example, with currencies, switch to integers, that is, instead of rubles, count in kopecks or fractions of kopecks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question