php 2 decimal places without rounding

Solutions on MaxInterview for php 2 decimal places without rounding by the best coders in the world

showing results for - "php 2 decimal places without rounding"
Neele
18 Apr 2019
1<?php 
2function cutAfterDot($number, $afterDot = 2){
3$a = $number * pow(10, $afterDot);
4$b = floor($a);
5$c = pow(10, $afterDot);
6echo "a $a, b $b, c $c<br/>";
7return $b/$c ;
8}
9echo cutAfterDot(2.05,2);
10
11/*
12output =   a 205, b 204, c 100 
132.04
14*/
15
16?>
Sophia
22 Mar 2018
1function cutNum($num, $precision = 2) {
2    return floor($num) . substr(str_replace(floor($num), '', $num), 0, $precision + 1);
3}