How to use str2double without rounding
64 views (last 30 days)
Hi , I know this could be a possible duplicate but all those solutions stated there didn't work for me. I am using the str2double function and it always rounds the conversion to the 4 places after the decimal point. Do you guys have any idea on converting the whole string exactly the way it is without rounding ??
Nut on 20 Jan 2017
maybe you need a proper set of the output display format:
The default format is "short", with the "long" format you can see more digits, look at the following example.
A = '0.219033048405430510873439814';
>> format long
More Answers (1)
Stephen23 on 20 Jan 2017
Edited: Stephen23 on 20 Jan 2017
str2double does not do any rounding: does its documentation mention "rounding" anywhere? In fact you are just getting confused by how numbers as displayed in MATLAB. How number values are displayed is a totally different thing to how they are stored in memory. str2double reads all of those digits correctly.
Use format to change how numbers are displayed:
>> format shortg
ans = 0.12346
>> format longg
ans = 0.123456789012346
There are plenty of format options: read the documentation and try some. Note that the double type is limited as to how many digits of precision it can handle. This is also not str2double's fault.