how to remove exponential value from a number

1 回表示 (過去 30 日間)
Rajashree Annapillai
Rajashree Annapillai 2018 年 8 月 26 日
コメント済み: Image Analyst 2022 年 8 月 23 日
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 件のコメント
Rajashree Annapillai
Rajashree Annapillai 2018 年 8 月 26 日
Exponent is not same throughout the program.It differs accordingly with the input value
Image Analyst
Image Analyst 2018 年 8 月 26 日
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 日
Try this:
a = 4.5236e+15
b = a / 10^floor(log10(a))
fprintf('b = %g\n', b)
  3 件のコメント
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
Image Analyst
Image Analyst 2022 年 8 月 23 日
@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 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by