如何在不损失精度的情况下截断十进制值 [英] How to truncate decimal value without loosing precision
本文介绍了如何在不损失精度的情况下截断十进制值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有当前变量php:
$latlng = "<a href='http://www.google.com/maps/place/".$lat.",".$lng."/@".$lat.",".$lng.",".$zoom."' target='_blank'>Lat ".$lat." Lng ".$lng."</a>";
回声输出如下例:
我想截断它所以最后我想得到以下结果:
i want truncate it so at end i want have following result:
我尝试了以下代码,但仅剪切了最后一部分:
I have tried following code but it cut only final part:
$cut_string = substr($latlng,0,strpos($latlng,'</a>')-12);
echo "$cut_string <br/>\r\n";
谢谢
推荐答案
我想我理解您的问题。
您是否希望链接具有完全的精度但易于阅读的链接文本?
I think I understand your problem.
You want the link with full precision but a easy to read link text?
这应是您所需要的:
$latlng = "<a href='http://www.google.com/maps/place/".$lat.",".$lng."/@".$lat.",".$lng.",".$zoom."' target='_blank'>Lat ".round($lat,3)." Lng ".round($lng,3)."</a>";
您可以看到google的链接是完整的,但文本四舍五入到了小数点后三位。
As you can see the link to google is intact but the text is rounded to three decimals.
这篇关于如何在不损失精度的情况下截断十进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文