# Methods to fix values to two decimals

5 Ansichten (letzte 30 Tage)
Jay am 12 Sep. 2017
Kommentiert: Jay am 12 Sep. 2017
Does anyone know the most efficient way to fix values to two significant figures?
I am trying to proof a calculations which initially has the calculated values to two significant figures and then has the final values to 7 significant figures.
When researching I found a MatLab answer stating that you can not fix "binary floating point arithmetic" https://au.mathworks.com/matlabcentral/answers/16882-how-to-round-the-decimal-point
Does MatLab cater for fixed point instead of just floating points?
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Walter Roberson am 12 Sep. 2017
Bearbeitet: Walter Roberson am 12 Sep. 2017
You can use the Fixed Point Toolbox.
You can also use the Symbolic Toolbox, but only if you convert the values into ratios, such as converting 0.23 to 23/100 (which sym() can do automatically for you.) If you use symbolic floating point numbers then there are situations where the calculation could be done in binary with the inexact representation problems you have heard about already.
When doing calculations to such limited precision, you need to think carefully about whether you want to round values or truncate values, and if you do want to truncate values, do you want to truncate towards 0 or do you want to truncate towards negative infinity ? For example if 0.236 is rounded towards 0 or negative infinity then that would become 0.23, but if -0.236 is rounded towards 0 that would be -0.23 whereas rounding towards negative infinity would be -0.24
##### 3 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
Walter Roberson am 12 Sep. 2017
Are you certain that is what you want? Consider -0.954 and -0.955 . For -0.954 the third decimal place < 5 so you want it to round down, which would be to -0.96 . For -0.955 the third decimal place is not < 5 so you want it to round up, which would be to -0.95 . This is a rounding scheme I have ever seen in use!
Jay am 12 Sep. 2017
I see, thankyou.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by