• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[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
 
Level 7
Joined
Mar 8, 2009
Messages
360
What I should do is setting num = value*100 and den = 100.
And then trying to simplify(don't know good english word) the fraction. Maybe dividing num and den by numbers that give modulus 0 on both numbers. You could do that with a loop that checks all prime numbers from 2 till half of current den.
 
Status
Not open for further replies.
Top