필터 지우기
필터 지우기

How to round the decimal?

조회 수: 2 (최근 30일)
laith Farhan
laith Farhan 2018년 6월 27일
댓글: Star Strider 2018년 6월 27일
Dear All;
I have a number array x = [0.00135678 0.00076243;0.0000045789 0.01234567];
Then i just want to round x to become as: results:[0.0013 0.00076; 0.0000045 0.012];
What to do?
Thanks in advance.....

채택된 답변

Star Strider
Star Strider 2018년 6월 27일
Try this:
x = [0.00135678 0.00076243;0.0000045789 0.01234567];
L10 = log10(x); % Base 10 Logarithm
mant = fix(10.^rem(L10,1)*100); % Calculate Mantissa & Remove Extra Digits
expt = floor(L10)-1; % Determine Exponent
Result = mant .* 10.^expt
Result =
0.001300000000000 0.000760000000000
0.000004500000000 0.012000000000000
  댓글 수: 2
laith Farhan
laith Farhan 2018년 6월 27일
Dear Star Strider Thanks alot for your help. its work 100%
thanks again
Star Strider
Star Strider 2018년 6월 27일
As always, my pleasure.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Steven Beumer
Steven Beumer 2018년 6월 27일
편집: Stephen23 2018년 6월 27일

카테고리

Help CenterFile Exchange에서 Elementary Math에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by