Effacer les filtres
Effacer les filtres

How do i convert scientific notation into number in matlab

350 vues (au cours des 30 derniers jours)
Jasmeet Kaur
Jasmeet Kaur le 10 Août 2016
Commenté : Walter Roberson le 11 Sep 2020
a=9.22222e+15
I need to convert this number and want to save the answer in variable
  1 commentaire
Stephen23
Stephen23 le 10 Août 2016
Modifié(e) : Stephen23 le 10 Août 2016
"I need to convert this number"
what do you want to convert to:
  1. a string
  2. another numeric class
  3. something else... ?

Connectez-vous pour commenter.

Réponses (3)

Stephen23
Stephen23 le 10 Août 2016
Modifié(e) : Stephen23 le 10 Août 2016
The variable a is already a numeric:
>> a = 9.22222e+15
a = 9.2222e+015
>> isnumeric(a) %check that it is a numeric
ans = 1
>> fprintf('%.0f\n',a)
9222220000000000
Why do you think that it is not a numeric ? You might like to read about the different format options, which control how numeric values are displayed in MATLAB:
Remember that how a numeric value is displayed is a totally different matter to how it is stored. For example, here are three different ways of displaying your numeric value:
>> format bank
>> a = 9.22222e+15
a = 9222220000000000.00
>> format hex
>> a = 9.22222e+15
a = 434061c7b591fc00
>> format longg
>> a = 9.22222e+15
a = 9.22222e+015
  7 commentaires
Stephen23
Stephen23 le 13 Sep 2017
Modifié(e) : Stephen23 le 13 Sep 2017
"MATLAB understand a value such as 1.0400e+4 as the whole number 10400 that it is, instead of as a non-whole number."
It certainly looks like a whole number:
>> sprintf('%.30f',1.0400e+4)
ans =
10400.000000000000000000000000000000
>> rem(1.0400e+4,1)==0
ans =
1
How would you expect it to be different from this?
"I believe what Jasmeet was asking is..."
Jasmeet did not mention "integer" or "whole" anywhere, and gave an example value that is slightly higher than flintmax, making the output value rather meaningless in terms of "whole number or not". If that is what Jasmeet and yourself are asking about then the solution is to learn about the properties of floating point numbers

Connectez-vous pour commenter.


Anish Vaidya
Anish Vaidya le 26 Nov 2017
Modifié(e) : Anish Vaidya le 26 Nov 2017
Even, I've the same problem. I want to store a number in a variable in decimal notation and then convert to array of characters.
  1 commentaire
Walter Roberson
Walter Roberson le 26 Nov 2017
What form is the value in at present?
When you convert it to character, how many decimal places of precision do you need?
What is the range of values possible?

Connectez-vous pour commenter.


Surama Biswas
Surama Biswas le 11 Sep 2020
Following example by Stephen Cobeldick works for me. I need to place each bit by last fprintf in an array. Please help me. Thanks in advance.
>> a = 9.22222e+15
a = 9.2222e+015
>> isnumeric(a) %check that it is a numeric
ans = 1
>> fprintf('%.0f\n',a)
9222220000000000
  2 commentaires
Walter Roberson
Walter Roberson le 11 Sep 2020
b = sprintf('%.0f', a)
Walter Roberson
Walter Roberson le 11 Sep 2020
Note that the result would be a character vector.
If the task is to store numeric 9222220000000000 as a double precision variable, then a = 9.22222e+15 already does that. The way that a variable displays is not the same thing as the value stored in the variable.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by