I
I
issssrt2016-06-16 16:27:31
PHP
issssrt, 2016-06-16 16:27:31

How to round up the price correctly?

I import the price from the price list using phpExcel
In a loop, getting the price of each column:

$price = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow(4, $i)->getValue();

Some cells with a price are not imported correctly, for example, the price has a price of 543.81 , and the library displays this way when outputting 543.8099999999999
round() also does not respond to such a price. Maybe someone faced this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2016-06-16
@alsopub

Alternatively, round to two decimal places:

$n = '543.8099999999999';
echo(round($n*100)/100);

A
Anton B, 2016-06-16
@bigton

see sprintf

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question