PHP Problem: floating point precision - BC Math & Round

Published on 2021-05-20


<?php

// Problem:
var_dump( 2161.06+1498.47 );
// result (error): float(3659.5299999999997)

// Solution with BC Math:
var_dump( bcadd('2161.06', '1498.47', 13) );
// result (success): string(18) "3659.5300000000000"

PHP Problem: floating point precision. Solution: BC ... [...]