四舍五入为有效数字 [英] Rounding to n significant digits
问题描述
我试图在MATLAB中编写代码,将数字整数(如我要求的)有效数字。
我不知道该怎么做。有什么建议?
转到 d
有效数字:
>> d = 3; %//位数
>> x = 5.237234; %//示例编号
>> D = 10 ^(d-ceil(log10(x)));
>> y = round(x * D)/ D
y =
5.2400
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' >> d = 3; %//位数
>> x = 5.237234; %//示例编号
>> D = 10 ^ d;
>> y = round(x * D)/ D
y =
5.2370
编辑
其实它更简单: I'm trying to write code in MATLAB that will round number to certain (as I ask) significant digits. I'm not sure how to do it. Any suggestions? To round to To round to EDIT Actually it's easier: the
这篇关于四舍五入为有效数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
>> d = 3;
>> x = 5.237234;
>> y = round(x,d,'significant')
y =
5.2400
>> d = 3;
>> x = 5.237234;
>> y = round(x,d)%//或y = round(x,d,'decimals')
y =
5.2370
d
significant digits:>> d = 3; %// number of digits
>> x = 5.237234; %// example number
>> D = 10^(d-ceil(log10(x)));
>> y = round(x*D)/D
y =
5.2400
d
decimal digits:>> d = 3; %// number of digits
>> x = 5.237234; %// example number
>> D = 10^d;
>> y = round(x*D)/D
y =
5.2370
round
function supports these options:>> d = 3;
>> x = 5.237234;
>> y = round(x, d, 'significant')
y =
5.2400
>> d = 3;
>> x = 5.237234;
>> y = round(x, d) %// or y = round(x, d, 'decimals')
y =
5.2370