Comment afficher une valeur en fraction?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
j'ai un decimal 0.3333, comment l'afficher en fraction?
Je veux avoir 1/3
0 commentaires
Réponses (1)
Mathieu NOE
le 17 Avr 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 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!