Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a num::Rational to a decimal number?

Tags:

rust

I'm trying to use the external library num with the goal to convert fractions to arbitrarily long decimal points, however, by reading the docs, I cannot find some clarifying example to convert a fraction to a decimal number. Anyone know how?

like image 513
Vikaton Avatar asked Nov 09 '22 20:11

Vikaton


1 Answers

I think that printing out arbitrary precision decimals is simply a hard problem. I don't see that the GNU Multiple Precision (GMP) Arithmetic Library supports this functionality. While Rust isn't built on top of GMP, if GMP doesn't have it I wouldn't expect Rust to have it.

The best you may be able to do is divide the numerator by the denominator yourself...

like image 155
Shepmaster Avatar answered Dec 19 '22 22:12

Shepmaster