我怎样才能达到一定的浮点精度? [英] How can I round to a certain floating-point precision?

查看:134
本文介绍了我怎样才能达到一定的浮点精度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这是一个简单的问题。我想:

  a = 1.154648126486416; 

成为:

  a = 1.154; 

而不是:

  a = 1.15000000000; 

如何在不使用 format('bank' code>。

解决方案

您可以这样做:

  a = floor(a * 1000)/ 1000; 


I think it's a simple question. I want:

a = 1.154648126486416;

to become:

a = 1.154;

and not:

a = 1.15000000000;

How do I do that without using format('bank').

解决方案

You could do this:

a = floor(a*1000)/1000;

这篇关于我怎样才能达到一定的浮点精度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆