Borrar filtros
Borrar filtros

Rounding a decimal down

3 visualizaciones (últimos 30 días)
L'O.G.
L'O.G. el 2 de Dic. de 2022
Comentada: Emre Tas el 8 de Ag. de 2023
With round(x,2) I can round a number to the nearest hundredth, but how do I round down to the nearest hundredth? For example, both 0.143 and 0.147 should become 0.14.

Respuesta aceptada

Matt J
Matt J el 2 de Dic. de 2022
Editada: Matt J el 2 de Dic. de 2022
x=0.147;
floor(x*100)/100
ans = 0.1400
  1 comentario
Emre Tas
Emre Tas el 8 de Ag. de 2023
Thank you for your answer, it solved my meshing problem.

Iniciar sesión para comentar.

Más respuestas (2)

Les Beckham
Les Beckham el 2 de Dic. de 2022
x = [0.143 0.147];
floor(x*100)/100
ans = 1×2
0.1400 0.1400

Vilém Frynta
Vilém Frynta el 2 de Dic. de 2022
Editada: Vilém Frynta el 2 de Dic. de 2022
Example:
X = 0.143;
Y = sprintf('%.2f',X);
Y = str2double(Y)
Y = 0.1400
Someone ahd same question before. Next time, try to Google your question before asking.
  2 comentarios
Stephen23
Stephen23 el 3 de Dic. de 2022
Editada: Stephen23 el 3 de Dic. de 2022
It is more efficient to keep this in the numeric domain, rather than converting to text and back.
It also does not work, because SPRINTF rounds values to the nearest digit, it does not round down:
X = 0.147;
Y = sprintf('%.2f',X);
Y = str2double(Y) % Nope, definitely not rounded down.
Y = 0.1500
The answers from Matt J and Les Beckham are correct.
Vilém Frynta
Vilém Frynta el 3 de Dic. de 2022
True, I just reffered to someone else's answer.

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by