ruby - How to solve Mathematical Expressions in Rails 4 like 6000*70%? -


i using dentaku gem solve little complex expressions basic salary 70% of gross salary. formulas user editable worked on dentaku.

when write calculator = dentaku::calculator.new initialize , enter command calculator.evaluate("60000*70%") error comes below:

dentaku::parseerror: dentaku::ast::modulo requires numeric operands /users/sulman/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/dentaku-2.0.8/lib/dentaku/ast/arithmetic.rb:11:in `initialize' 

i have array formula stored like: ["earningitem-5","*","6","7","%"] earningitem-5 object , has value 60000

how can resolve such expressions?

for particular case can use basic_salary = gross_salary * 0.7

next need create number field in views accepts 0..100 range. @ last, set after_save callback , use code:

model

after_create :percent_to_float  protected  def percent_to_float   self.percent = percent / 100.0   self.save end 

edit: of course, can use formula without callbacks:

basic_salary = gross_salary / 100.0 * 70 

where 70 user defined value.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -