How do I add commas to numbers using fprintf?
135 views (last 30 days)
Show older comments
Hello,
How do I add commas to numbers using fprintf? My customer wants me to write out tables and have commas in the numbers to better read it. For instance, 123456789.0 would be written out as 123,456,789.0. Thanks.
Best regards,
Bill Rooker
0 Comments
Accepted Answer
More Answers (3)
Ted Shultz
on 13 Jun 2018
function numOut = addComma(numIn)
jf=java.text.DecimalFormat; % comma for thousands, three decimal places
numOut= char(jf.format(numIn)); % omit "char" if you want a string out
end
Hope that helps! --ted
5 Comments
Jim Svensson
on 15 Feb 2021
I feel that in 2021 this functionality should be supported by sprintf/fprintf.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!