Comment afficher une valeur en fraction?
3 views (last 30 days)
Show older comments
j'ai un decimal 0.3333, comment l'afficher en fraction?
Je veux avoir 1/3
0 Comments
Answers (1)
Mathieu NOE
on 17 Apr 2025
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 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!