how to tell php to round up to the nearest tenth code example

Example 1: php float precision

<?php
var_dump(round(3.4)); // =>3
var_dump(round(3.5)); // =>4
var_dump(round(3.6)); // =>4
var_dump(round(3.6, 0)); // =>4
var_dump(round(5.045, 2)); // =>5.05
var_dump(round(5.055, 2)); // =>5.06
var_dump(round(345, -2)); // =>300
var_dump(round(345, -3)); // =>0
var_dump(round(678, -2)); // =>700
var_dump(round(678, -3));  // =>1000
?>

Example 2: round to 2 decimal places php

round(520.34345, 2);   // 520.34

Tags:

Php Example