简体   繁体   English

PHP格式编号不带舍入

[英]PHP format number without round

I Need to format a number for a Mysqli query. 我需要格式化一个Mysqli查询的数字。

it can be [1] [1.1] [1.111111..] and has to be the format [1.10] later. 它可以是[1] [1.1] [1.111111 ..],并且以后必须为[1.10]格式。

i tried to use number_format($number, 2, ',', ' '); 我试图使用number_format($number, 2, ',', ' '); wich actually works. 非常有效。

But the Problem is, this rounds up. 但是问题是,这四舍五入。 eg. 例如。 for 1.555555555, it does 1.56 as result. 对于1.555555555,结果为1.56。 is there a way to just format it to 2 decimals without rounding? 有没有一种方法可以将其格式化为2位小数而不四舍五入? like just delete everything afert the 2nd decimal? 像只是删除第二个小数点后的所有内容?

Do you mean the following? 您是说以下意思吗?

<?php
 $number = 1.956;
 $number_floored = floor($number*100)/100;
 echo $number_floored; //1.95
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM