Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to round to two decimal places PHP

I would like to round a number to two decimal places in PHP.

PHP code:

$bmi = ($form_state[values][submitted][1] * 703) / 
    ($form_state[values][submitted][10] * $form_state[values][submitted][10]);
$form_values['submitted'][11] = $bmi;
$form_values['submitted_tree'][11] = $bmi;

What is the best way to round the variable $bmi?

like image 952
jeremy Avatar asked Dec 09 '25 01:12

jeremy


1 Answers

round ($your_variable, 2)

https://www.php.net/manual/en/function.round.php

like image 172
bensiu Avatar answered Dec 10 '25 14:12

bensiu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!