Search code examples
mathfloating-pointfractions

Genius Math Tool: How to display fraction answers as decimal?


When I do some calculations with genius I get the answers as fractions. For example:

genius> 1-((3/4)^4)
= 
175
---
256

or

genius> 10/54
= 5/27

How do I get the answers as a normal floating point/decimal number? For example 5/27 = 0.185185185185


Solution

  • You can use float() to turn a number into a float. It is listed in the Numeric section of the help.

    genius> help float
    float (x)
    Description: Make number a float

    genius> 5/27
    = 5/27
    genius> float(ans)
    = 0.185185185185
    genius> float(5/27)
    = 0.185185185185
    

    From the manual in 5.1.1 Numbers, you will see that a division will create a special number type, a rational. You can avoid this by having one or both operands as floats, simply by appending .0.

    genius> 5.0/27
    = 0.185185185185