percentage #2

Closed
Doriginal opened this Issue Apr 22, 2012 · 3 comments

Projects

None yet

2 participants

@Doriginal

Good evening,
I am interested on how to calculate a percentage.
By modifying your code, I managed to calculate a percentage, to Siri.
But only one thing missing is that I can not include the word "percent".
The code works, saying "99 - 25" but does not work if you say "99 - 25%"
Could you help me?
I post the code I changed.
Thank's

def replus(re,ro,cal)
    rer = cleanup(re)
    ror = cleanup(ro)
    #rer = rerr if ( Float( rerr ) rescue false )
    #ror = rorr if ( Float( rorr ) rescue false )
    res = res.to_f
    res1 = res1.to_f
    res2 = res2.to_f
    res3 = res3.to_f
    print cal
    if cal == "+"
                      res1 = Decimal(rer) * Decimal(ror)
       res2 = (res1.to_f/100)
       res = (rer.to_f) - (res2.to_f)
    end
    @vor = rer
    @nach = ror
    @res = res.to_s.sub( ".", "," )
    @res3 = res.to_s.sub( ".", "," )
return rer,ror
end

listen_for /(test|testing) (.*)/i do |phrose,phrase|
@vor = 0
@nach = 0
@res = 0
ss = ""
ph = phrase.insert(0, " ")
ph = ph.to_s
if phrase.match(/( - )/)
ma = phrase.match(/( - )/)
vor = ma.pre_match.strip
nach = ma.post_match.strip
cal = "+"
replus(vor,nach,cal)
say @vor.to_s + " - " + @nach.to_s + " = " + @res.to_s, spoken: " " + @res.to_s

@muhkuh0815
Owner

just say 50 * 0,1 for 10% of 50

or the other way round make an
elsif for percent
or at least 2
like 5 percent from 10 loop and an 10 minus 5 percent
not sure how its said in english correctly

@Doriginal

I tried this, he said in response:
It's been 0.0

listen_for /(enlève|retire) (.*)/i do |phrose,phrase|
@vor = 0
@nach = 0
@res = 0
ss = ""
ph = phrase.insert(0, " ")
ph = ph.to_s
if phrase.match(/( - )/)
ma = phrase.match(/( - )/)
vor = ma.pre_match.strip
elsif phrase.match(/( \% )/)
ma = phrase.match(/( \% )/)
nach = ma.post_match.strip
cal = "+"
replus(vor,nach,cal)
say @vor.to_s + " - " + @nach.to_s + " = " + @res.to_s, spoken: " " + @res.to_s

@muhkuh0815
Owner

you need to set cal = "%"

and then in replus define the percent calculation

eg one with cal = "%from"
and one with cal ="-%"

then in replus

make elsif cal == "%from"
res = Decimal(rer) * hmmm here you must find a way that you convert 50% into ,50 or 1% into 0,01

and then one elsif cal == "-%"
res = ...

@Doriginal Doriginal closed this May 24, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment