Add 1 to the least significant digit of a number in MATLAB -


example: 6.321: need 6.322. 5.14875: need 5.14876.

how can this?

if represent numbers floating point or double precision floating point, problem disaster.

if can read in number string (you mentioned number input command), do:

x = input('enter number: ','s'); decimal_place = find(fliplr(x)=='.',1) - 1;  x_val = str2double(x); if(~isempty(decimal_place))          y = x_val + 10 ^ -decimal_place; else % if there no decimal place, find first non-zero digit sigfig     warning('ambiguous number of significant digits');     first_nonzero_digit = find(fliplr(x)~='0',1);     if(~isempty(first_nonzero_digit))       y = x_val + 10 ^ (first_nonzero_digit - 1);     else       y = x_val + 1;     end end  disp('your new number is'); disp(y); 

example test runs:

enter number: 1.9 new number      2 enter number: 3510 new number      3520 enter number: 323.4374 number   323.4375 enter number: 0 number      1 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -