How I can modify the decimal numbers in a table's column?
56 views (last 30 days)
I have a table with different values like: 0.5, -0.300, -99, 5, 0, and so on. I want to use the output of this table in a hydrological model so I need to have all values in 1 decimal (even integer values, like 5).
Here is an example:
Are what I have, But I need something like this:
I tried something like format long, format long g, and format bank, but they weren't helpful. So if anyone knows the solution I would be grateful if tells me.
More Answers (1)
Awais Saeed on 5 Aug 2021
You want to display the numbers as shown or modify them? In case you want to modify them, you can use
number = -99.32345; % the number you want to modify
num_str = num2str(number); % convert it to string
[idx,~]=regexp(num_str,'[.]'); % search for decimal point
num_str(idx+2:end) = ; % delete everything from idx+2 till end
number = str2num(num_str) % convert result back to number
You can use this in a loop to modify all of your values.