Comment afficher une valeur en fraction?

3 views (last 30 days)
KINGANGA
KINGANGA on 17 Apr 2025
Answered: Mathieu NOE on 17 Apr 2025
j'ai un decimal 0.3333, comment l'afficher en fraction?
Je veux avoir 1/3

Answers (1)

Mathieu NOE
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);
The closest integer fraction to 0.33 with tolerance 1e-06 is 1/3

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!