call(back)
Algorithms & Data Structuresmedium

Round Numeric String Values

You are given numeric values as strings, for example "3.45", "-2.5", or "123456789123456789123456789.5". The values may be far too large for built-in integer or float types in most languages, and converting to float would lose precision — so treat this as pure string manipulation.

Round each value to the nearest integer, rounding half away from zero, and return the result as a string with no leading zeros and never "-0".

Example:

"3.45"  -> "3"      "2.5"   -> "3"      "-2.5"  -> "-3"
"-0.4"  -> "0"      "9.99"  -> "10"     "999.5" -> "1000"
"123456789123456789123456789.5" -> "123456789123456789123456790"

Part 2: given a comma-separated string of such values, return the comma-separated rounded values.

Asked at