sarfaraj
sarfaraj

Reputation: 31

PHP's bcmul() wrong result

Why is this outputting 0.99 and not 1?

<?php
    echo bcmul("2.54", "0.3937007874015748", 2);    // 0.99
    echo 2.54 * 0.3937007874015748;    // 1
?>

My PHP Version 7.4.33

Upvotes: 0

Views: 67

Answers (1)

tetthys
tetthys

Reputation: 166

bcmul("2.54", "0.3937007874015748", 2); // with scale 2, '2.54' * '0.39' = '0.99'

It's like calculating to N decimal places using a pen and paper with your hands.

Upvotes: 0

Related Questions