1

I have some numbers, for example:

1.1, 10, 2.2*1.0e+45, 2.2*1.0e-44

I do not know exact what is the next number will be but I want to remove the scientific part of the number, i.e. reduce each number in magnitude to the half-open interval [1,10).The output values have to be like:

1.1, 1, 2.2, 2.2

How to achieve this in MATLAB?

Carl Witthoft
  • 20,573
  • 9
  • 43
  • 73
Fly_back
  • 259
  • 1
  • 5
  • 16
  • You example is unclear. Are those numbers written in a string? If they are just numbers on MATLAB they do not have scientific notation, they are just shown like that to you (and you can change it with e.g. `format long g`). If you just want to remove all and just get the number, why is 10 not 1.0? – Ander Biguri Jan 13 '16 at 11:18
  • @AnderBiguri thx, I made a mistake, yes, it should be 1.0. – Fly_back Jan 13 '16 at 11:23
  • 1
    And ho wmany floating point digits do you want? would 123456789 be 1.23456789 or 1.2? – Ander Biguri Jan 13 '16 at 11:24
  • How would you do this mathematically? – sco1 Jan 13 '16 at 11:27
  • @Fly_back by the way, the numbers you are looking for are often called the [significand or the mantissa](https://www.wikiwand.com/en/Significand). – Dan Jan 13 '16 at 12:05

1 Answers1

6

Its as easy as finding the previous power of ten and divide by that.

num=123456789;

num/10^floor(log10(num));

ans=
>>1.23456789

Reference: Rounding to a power of 10

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120