scala - How to perform calculation given multiple types of numbers? -


i have numbers list go through it, , doing simple calculation 2 numbers:

i have numbera , numberb, , calculation im doing is:

val res = (numbera/numberb) * 100 

now, dont know type number, know float (with 2 nums after dot) or integer...

so want know syntax in scala calculate it?

currently have:

val num1 = (vatreclaimed.toint/vatpaid.toint) * 100 

but dont work, , cannot use toint guess since dont know type...

whats important me res hold right answer, if 2.3 * 4 res hold 9.2

thanksss!

when not know type only, number, have work numeric. numeric can convert numeric value double, float, int or long. precision recommend double:

def calc[a : numeric, b : numeric](a: a, b: b): double = (a.todouble / b.todouble) * 100 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -