フィルターのクリア

Round floating number without zeros

15 ビュー (過去 30 日間)
loes visser
loes visser 2016 年 11 月 24 日
コメント済み: loes visser 2016 年 11 月 24 日
Hi,
I have an array with multiple floating value's. I would like to round them to the nearest two digit number. I used
round(x,2)
This rounds 1.32456778 to 1.3200000. But I would like the result 1.32 (without the zeros). Because I want to display the value in a graph as text, and now it displays 1.320000E+00
qq = 24;
qw = 41.2;
y = sprintf('Vote = %d', round(x,2) );
qe = text(qq,qw,y, 'FontWeight', 'bold', 'FontSize', 8);
Can someone help me?
  1 件のコメント
Jos (10584)
Jos (10584) 2016 年 11 月 24 日
what is the variable x in your code?

サインインしてコメントする。

採用された回答

Jos (10584)
Jos (10584) 2016 年 11 月 24 日
Use %f as a format holder rather than %d, and specify the number of decimals, like this
x = 1.320001
sprintf('%.2f',x)
  1 件のコメント
loes visser
loes visser 2016 年 11 月 24 日
Thanks! This works!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by