Convert decimal to integer in Matlab or Simulink. (Not rounding)

So this may be a simple question. I have an input decimal .12345, and I want to do it 12345. Now this value can change, so I do not want to just multiply it by 100,000. For example, if the input value was .123 I want 123, If it was .3219 I I want 3219.

+4
source share
2 answers

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 floating point precision up to 16 digits ...

try f(.123)...

, , - . , uint64(f(x)) , .

+7

num2str, 0. num str2num:

f=@(x) str2num(subsref(num2str(x),struct('type','()','subs',{{1,3:numel(num2str(x))}})));

, ...

0

Source: https://habr.com/ru/post/1693709/


All Articles