Filter löschen
Filter löschen

Truncating a number without rounding

101 Ansichten (letzte 30 Tage)
wesso Dadoyan
wesso Dadoyan am 18 Aug. 2015
Kommentiert: Walter Roberson am 18 Aug. 2015
Is it possible to truncate a number in matlab without rounding it to the first decimal point? for example, 5.17 I want it to be 5.1 and not 5.2 Thanks

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 18 Aug. 2015
  1 Kommentar
Walter Roberson
Walter Roberson am 18 Aug. 2015
For negative values you need to figure out whether you want -5.17 to go to -5.1 or to -5.2 . If you want the truncation to be "at most" the original value, then you would use floor(a*10)/10 . If you want the truncation to be "closer to 0" then you would use fix() like Azzi shows.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by