convert any decimal number between 1 to 10 by multiplying the number with 10^n.
6 views (last 30 days)
Show older comments
I have to convert any decimal number between 1 to 10 by multiplying the number with 10^n. As for example, if a=12.345 it should be 1.2345*10^1 if a=2.345 it should be 9.2345*10^0 if a=0.345 it should be 0.345*10^1 if a=0.0345 it should be 3.45*10^2 How can i do that ?
Accepted Answer
Star Strider
on 19 Jul 2018
I wrote a little utility function for my own use a while back to do just that:
expstr = @(x) [x*10.^floor(1-log10(abs(x))) floor(log10(abs(x)))];
a = 12.345;
b = expstr(a)
b =
1.2345 1.0000
I leave the rest to you.
2 Comments
Star Strider
on 19 Jul 2018
My pleasure.
The first element calculates the mantissa by multiplying the argument by 10 raised to the integer power calculated by the absolute value of the base 10 logarithm of the argument rounded toward -Inf and subtracted from 1. The second element is simply the exponent of the argument, calculated as the absolute value of the base 10 logarithm of the argument rounded toward -Inf.
Experiment with the various parts of the calculations to see how they work.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!