Three-digit format

19 次查看(过去 30 天)
J T
J T 2020-8-21
Hello,
I am looking for a format such that:
fprintf( format , 1.1111111); gives 1.11
fprintf( format , 11.111111); gives 11.1
fprintf( format , 111.11111); gives 111
That is 3 digits in total regadless of the decimal point, thanks!

采纳的回答

Walter Roberson
Walter Roberson 2020-8-21
%.3g

更多回答(1 个)

Sara Boznik
Sara Boznik 2020-8-21
Hi
I suggest you that you use:
fprintf('%.3g',1.111111)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by