So this maybe an easy question. I have some incoming decimal .12345 and I want to make that 12345. Now this value can change so I dont want to just multiply it by 100,000. For example if the incoming value was .123 I want 123, If it was .3219 I want 3219.
here's something to play with: (assuming your input is a number (double or single)
f=@(x) x*10^sum(floor(x*10.^[0:16])~=x*10.^[0:16])
this assumes a floating point accuracy of up to 16 digits...
try f(.123)
...
an additional note, the output will look like an integer but it really is still a double\single. In order to really make it to an integer class one you'll need to cast with uint64(f(x))
or whatever integer type you need.
Another solution is to cast to string using num2str, take out the 0. and cast back to num using str2num:
f=@(x) str2num(subsref(num2str(x),struct('type','()','subs',{{1,3:numel(num2str(x))}})));
ugly but works...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With