0

I have the following string as my input:

(100m/10k) * 10k

where

m = 1,000,000
k = 1,000

I expect an output of

(100000000/10000) * 10000

I'm having a difficult time figuring out how to replace the abbreviated integers with "real integers". I've tried looping through each of the characters in the string and finding the letters that have a corresponding integer and multiplying them with the integer before it, but I'm having trouble with finding the integer before the letter, and replacing/inserting it in the correct spot.

uploak
  • 1
  • 2
    Can't you just `replace("m", "000000")` and so on? – shmosel Apr 06 '22 at 01:39
  • I can't believe I missed that, thank you. – uploak Apr 06 '22 at 01:40
  • Are you likely to have numbers like `2.5k` which has to become `2500`? – Dawood ibn Kareem Apr 06 '22 at 01:59
  • Depending on the complexity of your expressions you might consider writing a parser to evaluate the expression in postFix notation. Then as you encounter `k,m`, or even `g` you can push the appropriate value on the stack with the multiplicative operator. This would also take care of @DawoodibnKareem's question. – WJS Apr 06 '22 at 02:12
  • Please provide enough code so others can better understand or reproduce the problem. – Community Apr 06 '22 at 07:09

0 Answers0