How do i convert scientific notation into number in matlab

a=9.22222e+15
I need to convert this number and want to save the answer in variable

댓글 수: 1

Stephen23
Stephen23 2016년 8월 10일
편집: Stephen23 2016년 8월 10일
"I need to convert this number"
what do you want to convert to:
  1. a string
  2. another numeric class
  3. something else... ?

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

답변 (3개)

Stephen23
Stephen23 2016년 8월 10일
편집: Stephen23 2016년 8월 10일
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

I want to store answer in a variable
When you define
a = 9.22222e+15
then a is a variable, and it is numeric.
a=9.2222ee+15
I want covert the value of a in decimal form and store that decimal form in other vairable
@Jasmeet Kaur: so far I have shown you that a is a variable, and that it is numeric.
Can you please explain to me why you think that a is not a variable, and why you think think that a is not numeric. I suspect that you are getting confused between displaying a numeric value and the stored numeric value (i.e. a variable): storing and displaying numeric values are two totally different things. The variable that you have created is numeric, by the standard meaning of the word in MATLAB:
a = 9.22222e+15
MATLAB, like most programming languages, does not store numeric values as "decimal" but as binary, so I have no idea what you mean by "I want covert the value of a in decimal form". The value is stored as the closest binary representation of the number that you have given, which is the best that we can do unless we get into more complicated numeric formats. And of course you can display that value in many different ways, including some that you might call "decimal": I showed you some of different ways to change the format, did you try ?
These are such basic concepts that you really should start to learn MATLAB by doing the introductory tutorials:
I'm currently struggling with a similar issue. Although the variable a is indeed stored as a number, when trying to index with it for example MATLAB throws "Warning: Integer operands are required for colon operator when used as index" because it views the scientific notation as a decimal. I believe what Jasmeet was asking is how to make MATLAB understand a value such as 1.0400e+4 as the whole number 10400 that it is, instead of as a non-whole number.
"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

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

Anish Vaidya
Anish Vaidya 2017년 11월 26일
편집: Anish Vaidya 2017년 11월 26일

0 개 추천

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

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?

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

Surama Biswas
Surama Biswas 2020년 9월 11일

0 개 추천

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

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.

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

카테고리

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

질문:

2016년 8월 10일

댓글:

2020년 9월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by