I am trying to perform the following divison operation.
l = 2.093750000000000e+09;
l/10^9
It was giving the output as:
ans =
2.0938
But i need the output as 2.09375 only. How an i achieve it ? I want to use it in further calculations as 2.09375 only. Is there any way to achieve this ?
l = 2.187500000000000e+09;
l/10^9
This was giving desired output in this case.
ans =
2.1875
If anybody knows how to solve this, please share your thoughts.

回答 (1 件)

Arthur Roué
Arthur Roué 2020 年 9 月 30 日
編集済み: Arthur Roué 2020 年 9 月 30 日

0 投票

There is no problem here, the default display format is set to short. Try :
format long
l = 2.093750000000000e+09;;
l/10^9
ans =
2.093750000000000
You can also access to the variable with the variable inspector : just double click on your variable in the workspace explorer.

5 件のコメント

Mahesh Babu Dhanekula
Mahesh Babu Dhanekula 2020 年 9 月 30 日
I want this value n = l/10^9 in further calculations.
Will the value stored in "n" is 2.09375 ?
Mahesh Babu Dhanekula
Mahesh Babu Dhanekula 2020 年 9 月 30 日
It again become 2.0938 even after using format long on top of the code
Steven Lord
Steven Lord 2020 年 9 月 30 日
That's not what I'm seeing:
>> format
>> l = 2.093750000000000e+09;
>> x = l/10^9
x =
2.0938
>> format long
>> x
x =
2.093750000000000
>> format longg
>> x
x =
2.09375
Or is this related to your other question? The format function does NOT control how a number is converted into a string using string (either explicitly or implicitly by concatenating it with a string array using +.) For that you will need to use something that allows you to explicitly control the way the number is written as text like fprintf or num2str.
Mahesh Babu Dhanekula
Mahesh Babu Dhanekula 2020 年 9 月 30 日
Thanks for reading my 2 questions. This is exactly what i needed steven.
I have a number 2.093750000000000e+09, and I want to to covert this into 2.09375Hz. So how can i do this ?
If there is any way, please let me know steven
Steven Lord
Steven Lord 2020 年 9 月 30 日
Use fprintf or num2str to create a string or char vector with the desired format then concatenate it with the string "Hz" using +.

サインインしてコメントする。

カテゴリ

製品

リリース

R2020a

質問済み:

2020 年 9 月 30 日

コメント済み:

2020 年 9 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by