how to change the digit after decimal

7 ビュー (過去 30 日間)
Niki
Niki 2015 年 8 月 20 日
回答済み: Noam 2015 年 8 月 20 日
I have few vectors which they have values like below
1.2 222.55 etc
matlab shows that with so many digit , I dont want, evenI tried to correct this by hand in xls which makes me tired
is there any solution to for example remove all digits until 1 or 2 or 3 or as you wish you ?
for example if my vectors which consists of 300 values, I want to do it for all of them and not one number
Thanks

回答 (2 件)

Walter Roberson
Walter Roberson 2015 年 8 月 20 日
This is not actually possible in binary floating point arithmetic, because 1/10 is not exactly representable in binary. However, you can get close to it by using
digits = 3;
newvalue = round(value * 10^digits) / 10^digits;

Noam
Noam 2015 年 8 月 20 日
Try using format:
>> format long
>> ans
ans =
1.222200000000000 1.222200000000000
>> format short
>> ans
ans =
1.2222 1.2222
>> format bank
>> ans
ans =
1.22 1.22
>> format shortG
>> ans
ans =
1.2222 1.2222
>> format rat
>> ans
ans =
6111/5000 6111/5000

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by