Formatting a double for output in message box
5 views (last 30 days)
Show older comments
Mathias Wagner
on 24 Jan 2017
Commented: Mathias Wagner
on 24 Jan 2017
Hi,
in my program i have a message box, which informs the user that an activity has been terminated and also display the activities consumption. Something like this: 'The activity xxx has been terminated and the consumption was 4.925971e-01 kWh'
My problem: how do i get that (fairly) ugly and unreadable value '4.925971e-01' to the handy format of '0.492'?
Cheers, Mathias
0 Comments
Accepted Answer
Benjamin Kraus
on 24 Jan 2017
Edited: Benjamin Kraus
on 24 Jan 2017
sprintf('%0.3f',val);
Or, more completely:
sprintf('The activity %s has been terminated and the consumption was %0.3f kWh', activity, val);
More Answers (0)
See Also
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!