Problem Statement | |||||||||||||
You are a developer for a financial computer system. Users of the system often operate with large numbers, so it's important that numbers be formatted in an easy-to-read manner. You are given a String number containing the internal representation of a non-negative number. This number will contain only digits, along with an optional decimal separator represented by a comma (','). Format the number as follows: 1. If the number contains a decimal separator, replace the decimal separator with a period ('.'). 2. Divide the integer part of the number into groups of three consecutive digits, from right to left. Depending on the number of digits, the left-most group might only contain 1 or 2 digits. Insert a single space (' ') between each pair of consecutive groups. (The integer part of the number is the part of the number to the left of the decimal separator if one exists, or the entire number if there is no decimal separator.) For example, "1234567,890" would be formatted as "1 234 567.890" and "1024" would be formatted as "1 024". If insignificant leading or trailing zeroes exist in the number, they must be preserved. For example, "00003,1234000" would be formatted "00 003.1234000". Return the formatted version of the given number. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- | number will contain between 1 and 50 characters, inclusive. | ||||||||||||
- | Each character in number will be either a digit ('0'-'9') or a comma (','). | ||||||||||||
- | number will contain at most one comma (','). | ||||||||||||
- | Comma (',') will not be the first or the last character of number. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
|