Timeline for Calculating number of digits in the integer part in a decimal number
Current License: CC BY-SA 3.0
9 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
S Jan 31, 2017 at 18:39 | history | suggested | SFDC Neuf | CC BY-SA 3.0 |
swapped log and abs: need to take the absolute value before doing the log function.
|
Jan 31, 2017 at 18:37 | review | Suggested edits | |||
S Jan 31, 2017 at 18:39 | |||||
Jan 31, 2017 at 18:19 | comment | added | Adrian Larson♦ | It wouldn't give the correct result for values between 0 (exclusive) and 1 (inclusive). | |
Jan 31, 2017 at 18:09 | comment | added | Derek F |
...and this, ladies, gentlemen, and those identifying as non-binary, is what we call an elegant solution. On that note, if you're just adding one to the floor, why not use Math.ceil() instead?
|
|
Jan 31, 2017 at 17:47 | history | edited | Adrian Larson♦ | CC BY-SA 3.0 |
added 304 characters in body
|
Jan 31, 2017 at 17:47 | comment | added | Adrian Larson♦ | Yeah adding that in my edit. | |
Jan 31, 2017 at 17:46 | comment | added | SFDC Neuf |
Shouldn't the return be (input == 0) ? 1 : 1 + (Integer)Math.floor(Math.log10(Math.abs(input))); ? The log function isn't defined for negative numbers.
|
|
Jan 31, 2017 at 17:31 | comment | added | Adrian Larson♦ | Will add more explanation shortly. | |
Jan 31, 2017 at 17:29 | history | answered | Adrian Larson♦ | CC BY-SA 3.0 |