MATLAB Answers

modifying/​rounding/a​proximatin​g a number

46 views (last 30 days)
Opariuc Andrei
Opariuc Andrei on 30 Oct 2020 at 1:20
Commented: Star Strider on 31 Oct 2020 at 12:48
i need a way to modify a number a=2.65987 into 2.6598 i tried round /fprintf , but both display as 2.6599 ,i need it badly ,i could just pop it out of nowhere by substracting 0.00007 but that's not helping .

  0 Comments

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 30 Oct 2020 at 1:35
One option:
c = floor(a*1E4)/1E4
producing:
c =
2.6598
.

  6 Comments

Show 3 older comments
Star Strider
Star Strider on 30 Oct 2020 at 3:12
It is likely not possible to go from 0.0000300 to 0.0000299 in the absence of floatiing-point approximation error, or otherwise subtracting eps or some other very small number from the original number. See the documentation section on Floating-Point Numbers for an extensive discussion of them.
I am certain she will know!
Opariuc Andrei
Opariuc Andrei on 31 Oct 2020 at 11:01
i checked , she doesn't know , i gave her something to ponder about :) / homework
Star Strider
Star Strider on 31 Oct 2020 at 12:48
Interesting!
Check the link I posted — the link information is correct.
While I would normally suggest that the difference between the two in the precision of the diaplayed numbers could account for the difference, that is not the situation here, where the display precision is not changing.

Sign in to comment.

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by