Timeline for adding the digits of a number
Current License: CC BY-SA 3.0
        21 events
    
    | when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Mar 10, 2015 at 20:19 | comment | added | user170800 | Thank you guys for the help. it is much appreciated. thank you MichaelT for pointing me in the right direction. and also Whatsisname and Steven Burnap for suggesting an alternative that worked. thanks guys :)) | |
| Mar 10, 2015 at 20:17 | comment | added | user170800 | So if I got it right after reading a bit about it. When I do "5.0 - 5" it doesn't really become zero due to precision problems so instead it might store 0.0000000000009328482 or something like that, which is the reason why my "while number > 0" statement is still running even though I expected it to hit zero and stop. | |
| Mar 10, 2015 at 20:09 | vote | accept | user170800 | ||
| Mar 10, 2015 at 20:01 | comment | added | user40980 | @user170800 you may wish to delve into the floating-point tag and see other similar questions. I've got an answer elsewhere that my help you: When do rounding problems become a real problem? Is the least significant digit being one off really a big deal? (and can work on explaining what is going on at the bit level later). | |
| Mar 10, 2015 at 19:50 | answer | added | user53141 | timeline score: 2 | |
| Mar 10, 2015 at 19:40 | comment | added | user170800 | getting the result is less important to me, I just wanted to know why the problem occurs. | |
| Mar 10, 2015 at 19:39 | comment | added | user170800 | whatisname I wanted to avoid that actually but that would be simpler, I agree. | |
| Mar 10, 2015 at 19:37 | comment | added | whatsisname | Just output the number to a string and go through it char by char. | |
| Mar 10, 2015 at 19:04 | comment | added | 5gon12eder | Wouldn't this question be more appropriate on Stack Overflow? | |
| Mar 10, 2015 at 18:35 | comment | added | user40980 | (I'm not a python person, nor do I have python at my disposal here to explain it - I'm a Java / Perl guy and I looked for "big decimal python" to find that. Its kin in Java is BigDecimal and perl is Math::BigFloat - once you know what to look for, its easy to find the corresponding class in another language) | |
| Mar 10, 2015 at 18:31 | comment | added | user40980 | I'd start by reading the document on the decimal type. | |
| Mar 10, 2015 at 18:31 | comment | added | user40980 | @bigstones while code block formatting does work for that edit, it also enables syntax highlighting (which is incorrect on output) and doesn't help with the readability. | |
| Mar 10, 2015 at 18:31 | comment | added | user170800 | How can i fix it then? | |
| Mar 10, 2015 at 18:29 | review | Suggested edits | |||
| Mar 10, 2015 at 18:30 | |||||
| Mar 10, 2015 at 18:29 | comment | added | user40980 | And that is your problem. You may wish to read docs.python.org/2/library/decimal.html | |
| Mar 10, 2015 at 18:28 | comment | added | user170800 | I am storing the number as a float | |
| Mar 10, 2015 at 18:28 | history | edited | user40980 | CC BY-SA 3.0 | 
                
                    formatting. 
                
             | 
| Mar 10, 2015 at 18:27 | comment | added | user40980 | What type are you storing the number in? | |
| Mar 10, 2015 at 18:27 | comment | added | user170800 | sorry, when I wrote the question the formatting wasn't messed up like that | |
| Mar 10, 2015 at 18:26 | review | First posts | |||
| Mar 10, 2015 at 20:37 | |||||
| Mar 10, 2015 at 18:25 | history | asked | user170800 | CC BY-SA 3.0 |