How to remove zeros from double value?

조회 수: 9 (최근 30일)
Mira le
Mira le 2022년 12월 18일
답변: Walter Roberson 2022년 12월 18일
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
Walter Roberson
Walter Roberson 2022년 12월 18일
format bank
perhaps?
Walter Roberson
Walter Roberson 2022년 12월 18일
... No, it turns out that format bank rounds

댓글을 달려면 로그인하십시오.

답변 (2개)

VBBV
VBBV 2022년 12월 18일
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
Dyuman Joshi
Dyuman Joshi 2022년 12월 18일
This won't work with random data, it depends on manually putting the values

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2022년 12월 18일
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

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

태그

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by