If a=4.5236e+15 ,then I want to print the result as b = 4.5236 alone by eliminating the exponential value.How can I do this.Please anyone help me .

댓글 수: 3

Haritha, there is an official "Answers" section below where you can get credit (reputation points) for your answers. Up here, it's supposed to be for people to ask for clarification of the original posting. You might want to consider moving your answer to the Answers section below.
Exponent is not same throughout the program.It differs accordingly with the input value
But my answer below takes that into account.
Please post your number where my answer below does not work.

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

 채택된 답변

Image Analyst
Image Analyst 2018년 8월 26일

0 개 추천

Try this:
a = 4.5236e+15
b = a / 10^floor(log10(a))
fprintf('b = %g\n', b)

댓글 수: 3

Thank you so much sir..Its working...
Ajin R.
Ajin R. 2022년 8월 23일
편집: Ajin R. 2022년 8월 23일
It works well ! Thanks to Image Analyst. But for negative numbers, it gives complex number as output.
For eg:-
a = -4.5236e+15
b = a / 10^floor(log10(abs(a)))
fprintf('b = %g\n', b)
Output:
b =
3.0227 + 3.3655i
b = 3.02274
Following the answer from Image Analyst, we may rewrite the same as:
a = -4.5236e+15
b = a / 10^floor(log10(abs(a)))
fprintf('b = %g\n', b)
Output:
b =
-4.5237
b = -4.5237
@Ajin R. Not sure what you meant, but the output is not what you said it was. Look:
% First code snippet:
a = -4.5236e+15;
b = a / 10^floor(log10(abs(a)))
b = -4.5236
fprintf('b = %g\n', b)
b = -4.5236
% Second code snippet:
a = -4.5236e+15;
b = a / 10^floor(log10(abs(a)))
b = -4.5236
fprintf('b = %g\n', b)
b = -4.5236

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by