11
0
In this challenge, you will write a program to output how many decimal places are in the input string and trim the input if needed.
Examples
-12.32
2
32
0
3231.432
3
-34.0
0 -34
023
0 23
00324.230
2 324.23
10
0
00.3
1 0.3
0
0
-04.8330
3 -4.833
Rules
- Input will be a string which can be taken through, STDIN, function arguments or the closest equivalent
- Output can be through function return, STDOUT, or the closest equivalent.
- There is no limit on the size for the input integer except for your languages maximum string length.
- If the input has any unnecessary (leading or trailing) zeros:
- You should take them out
- Output the amount of decimal place in the new number
- Output the new number separated by a separator (e.g. space, newline, comma)
- Input will always match this RegEx:
-?\d+(\.\d+)?
, or if you don't speak RegEx:- There could be a
-
at the beginning implying a negative number. Then there will be at least one digit. Then there could be... a.
and some more digits. - To check if an input is valid, check here
- There could be a
- No Regex
This is code-golf so shortest code in bytes wins
Maybe add a test case with minus sign and leading zeros? – Luis Mendo – 2016-01-17T22:48:23.753
Is it allowed to output the final number regardless whether it was trimmed or not? – insertusernamehere – 2016-01-17T22:52:11.343
1@insertusernamehere no you can only output the second number if it has been trimmed – Downgoat – 2016-01-17T22:59:22.560
@nimi whoops that was a typo. I meant "number of decimal places" – Downgoat – 2016-01-17T23:00:53.497
1You may want to add a test case/example for a single
0
. – insertusernamehere – 2016-01-17T23:01:22.327What should the output for
-0
be? – user81655 – 2016-01-18T02:39:01.477@user81655 Just
0
– Downgoat – 2016-01-18T02:39:19.263@CᴏɴᴏʀO'Bʀɪᴇɴ If the operator matches the semantic definition of a Regular Expression as defined here then it is not allowed
– Downgoat – 2016-01-18T19:05:22.0673-1 for the pointless regex restriction. – Conor O'Brien – 2016-01-18T19:10:00.117
@CᴏɴᴏʀO'Bʀɪᴇɴ Just to explain, I added that to avoid trivial answers – Downgoat – 2016-01-19T00:44:58.927
@Doᴡɴɢᴏᴀᴛ I now see that Regex can trivialize an answer. Sorry, +1ing (could you edit, or something?) – Conor O'Brien – 2016-01-19T00:47:45.137