如何将数字近似为n个小数位? [英] How to approximate a number to a n number of decimal places?

查看:69
本文介绍了如何将数字近似为n个小数位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几周前,我已经开始在OS X的 wxMaxima 接口上使用 maxima (实际上我已经使用了几次).

我试图在网上找到解决方案,但是也许是因为我是盲人,或者可能是因为我没有在maxima的官方文档中进行搜索的丰富经验,所以还没有找到具体的解决方案./p>

如何将数字近似为 n 个小数位?例如,如果我使用 float(22/7),它会给我这个巨大的数字 3.142857142857143 ,但是我只想例如将其近似到小数点后三位<代码> 3.143 .

解决方案

fpprec 控制Maxima bigfloat中有效数字的实际数量.这仅适用于bigfloat,不适用于普通(固定精度,IEEE 754)浮动.

另请参见 fpprintprec ,它控制要打印的位数,该数字适用于bigfloat和普通的float.因此,另一个适合您的解决方案是:

 (%i1)fpprintprec:4 $(%i2)浮动(22/7);(%o2)3.143 

I have started using maxima just a few weeks ago (actually I have just used it a few times) with the wxMaxima interface for OS X.

I have tried to find a solution for this around the web, but maybe because I am blind or maybe because I do not have much experience in searching in the official documentation of maxima, I have not find a concrete solution yet.

How do I approximate a number to a n number of decimal places? For example, if I use float(22/7), it gives me this huge number 3.142857142857143, but I just want for example to approximate it to the 3rd decimal place 3.143.

解决方案

fpprec controls the actual number of significant digits in a Maxima bigfloat. That applies only to bigfloats and not to ordinary (fixed precision, IEEE 754) floats.

See also fpprintprec which controls how many digits are printed, which applies to bigfloats and to ordinary floats alike. So another solution for you is:

(%i1) fpprintprec : 4 $
(%i2) float (22/7);
(%o2)                                3.143

这篇关于如何将数字近似为n个小数位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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