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