Problem
I'm trying to create a tool that takes a number as input, for example - 1kk, and replaces each k with multiplication by 1000, i.e. here we get 1000000.
There's no problem when dealing with integers, but I'm struggling to implement and algorithm which will replace numbers with floating point like 12.345kk with 12345000.
Possible solution
Okay, I could replace each k with multiplication by 1000 and then eval the whole expression:
$inp= "12.345kk";
$number = preg_replace('/[kt]/','*1000',$inp);
eval("\$result = {$number};");
echo($result); // 12345000
but it's really dangerous since the tool takes user input, and user can write anything they want.
Could you provide a safe solution to this problem?
It's a PHP question, but I guess the solution should be more-or-less similar in other languages, an algorithm itself shouldn't be very difficult.