• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

[JASS] Getting a fraction from a decimal

Status
Not open for further replies.
Ok, so i want a Fraction object, simply because I find it easier to work in fractions than decimals personally. I want a method to work out a fraction from a decimal. How would I do this? (I know it's possible because my calculator can do it)
JASS:
library Fraction
    struct Fraction
        integer num
        integer den
        real value
        
        static method create takes integer num, integer den returns Fraction
            local Fraction f = Fractionn.allocate()
            
            set f.num = num
            set f.den = den
            set f.value = I2R(num)/I2R(den)
            
            return f
        endmethod
        
        static method createFromReal takes real value returns Fraction
            local Fraction f = Fraction.allocate()
            
            set f.value = value
            //what here???
            
            return f
        endmethod
    endstruct
endlibrary
 
Status
Not open for further replies.
Top