Comment afficher une valeur en fraction?
2 ビュー (過去 30 日間)
古いコメントを表示
j'ai un decimal 0.3333, comment l'afficher en fraction?
Je veux avoir 1/3
0 件のコメント
回答 (1 件)
Mathieu NOE
2025 年 4 月 17 日
Bonjour @KINGANGA
voici une possibilité :
% Given decimal number
decimalNumber = 0.33333333333;
% Find the closest integer fraction with specified tolerance
tolerance = 1e-6;
[numerator, denominator] = rat(decimalNumber, tolerance);
% Display the result
fprintf('The closest integer fraction to %.2f with tolerance %.e is %d/%d\n', decimalNumber, tolerance, numerator, denominator);
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!