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!