sprintf value into a specific format
3 ビュー (過去 30 日間)
古いコメントを表示
I have some values I'd like to sprintf into a specific format. It is similar to Fortran 77's F7.5 with an exponent.
Values:
x = 38178.873648
y = 895.258425
Desired output format:
x = 38.17887e+03
y = 89.52584e+01
sprintf('%.6e',x) and sprintf('%.6e',y) get me 3.817887e+04 and 8.952584e+02. Can I specify where the decimal point is in sprintf or do I have to put in a few extra lines of code?
Thanks for the help. Sorry if this is a bit of a newby question.
0 件のコメント
回答 (1 件)
Walter Roberson
2017 年 11 月 20 日
Sorry, sprintf() cannot control the number of digits before the decimal place when an exponent is used. Also, the number of digits in the exponent is not certain to be the same between MS Windows and Mac or Linux.
You will need to write some code that analyzes the number and prints in the format you want. (Watch out for 0. Watch out for negative numbers. Watch out for nan and inf.)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Numeric Types についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!