How to remove zeros from double value?
Mostrar comentarios más antiguos
hi every one
I have a set D that contains values in double?
D=0.2352, 0.5263
I want to display
D= 0.23, 0.52
Thak you
3 comentarios
I think the only way to do it for numeric value is to change the format.
format shortG
D=[0.2352, 0.5263]
d=floor(D*100)/100
Walter Roberson
el 18 de Dic. de 2022
format bank
perhaps?
Walter Roberson
el 18 de Dic. de 2022
... No, it turns out that format bank rounds
Respuestas (2)
format shortG
D = [0.2352 0.5263]
D = round(D(:),3) - [0.005 0.006].'
1 comentario
Dyuman Joshi
el 18 de Dic. de 2022
This won't work with random data, it depends on manually putting the values
D = [0.2352, 0.5263];
d = floor(D*100)/100;
%version 1
fprintf('D = '); fprintf('%.2f, ', d(1:end-1)); fprintf('%.2f\n', d(end)); %must be one line for LiveScript
%version 2
disp("D = " + strjoin(compose("%.2f", d), ', '))
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!