How to remove zeros from double value?

6 vues (au cours des 30 derniers jours)
Mira le
Mira le le 18 Déc 2022
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 commentaires
Walter Roberson
Walter Roberson le 18 Déc 2022
format bank
perhaps?
Walter Roberson
Walter Roberson le 18 Déc 2022
... No, it turns out that format bank rounds

Connectez-vous pour commenter.

Réponses (2)

VBBV
VBBV le 18 Déc 2022
format shortG
D = [0.2352 0.5263]
D = 1×2
0.2352 0.5263
D = round(D(:),3) - [0.005 0.006].'
D = 2×1
0.23 0.52
  1 commentaire
Dyuman Joshi
Dyuman Joshi le 18 Déc 2022
This won't work with random data, it depends on manually putting the values

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 18 Déc 2022
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
D = 0.23, 0.52
%version 2
disp("D = " + strjoin(compose("%.2f", d), ', '))
D = 0.23, 0.52

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Tags

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by