RE: Remove integer from float number
Sorry about the Top Posting that I did before. It is just the style I am used to using, and I didn't realize that it was different here. I won't do it again. -- http://mail.python.org/mailman/listinfo/python-list
Re: Remove integer from float number
kpp9c wrote: okay... out of curiousity... how would you then seperate the interger value from the fractional part do something to one side and then put it back together... like if you had 8.01 and you want to add to the '8' part in one way (ordinary decimal) and add to the .01 part modulo something .. like say modulo 12 so that adding .11 to 8.01 would give you 9.0 ... I believe math.modf() may be what you're looking for. -- http://mail.python.org/mailman/listinfo/python-list
Re: Remove integer from float number
I think you ought to make your own class and define some of the special methods. mt -- http://mail.python.org/mailman/listinfo/python-list
Re: Remove integer from float number
Derek Basch wrote: How can I return: .666 from float: 0.666 This is what I have so far: %.6f % x Thanks Everyone, Derek Basch This works but I'm not entirely sure I know what you are trying to accomplish. (%.3f % x)[1:] -Larry Bates -- http://mail.python.org/mailman/listinfo/python-list
Re: Remove integer from float number
Ahh yes you have to put parenthases around the string formatting to remove the integer using indexes. Thanks, that's just what I needed! Derek Basch -- http://mail.python.org/mailman/listinfo/python-list
Re: Remove integer from float number
Derek Basch [EMAIL PROTECTED] writes: Ahh yes you have to put parenthases around the string formatting to remove the integer using indexes. Thanks, that's just what I needed! I think it's better to remove leading zeros explicitly: ('%.3x' % x).lstrip('0') -- http://mail.python.org/mailman/listinfo/python-list
Re: Remove integer from float number
On 24/03/2006 6:44 AM, Larry Bates wrote: Derek Basch wrote: How can I return: .666 from float: 0.666 This is what I have so far: %.6f % x Thanks Everyone, Derek Basch This works but I'm not entirely sure I know what you are trying to accomplish. (%.3f % x)[1:] x = 12345.666; (%.3f % x)[1:] '2345.666' I'm sure of neither what the OP is trying to accomplish nor what Larry's definition of works is :-) Perhaps the condition abs(x) 1.0 is implied ... -- http://mail.python.org/mailman/listinfo/python-list
Re: Remove integer from float number
John Machin wrote: On 24/03/2006 6:44 AM, Larry Bates wrote: Derek Basch wrote: How can I return: .666 from float: 0.666 This is what I have so far: %.6f % x Thanks Everyone, Derek Basch This works but I'm not entirely sure I know what you are trying to accomplish. (%.3f % x)[1:] x = 12345.666; (%.3f % x)[1:] '2345.666' I'm sure of neither what the OP is trying to accomplish nor what Larry's definition of works is :-) Perhaps the condition abs(x) 1.0 is implied ... For the example given, my code works. With so little information the only thing I could do is answer the specific question and caveat it that I don't know exactly what OP is trying to accomplish. By the OPs response to my post, it was what he was looking for. But I agree it is very much an edge-case question. -Larry Bates -- http://mail.python.org/mailman/listinfo/python-list
Re: Remove integer from float number
With that terse description and the subject line I would interpret the OP like so: print re.sub(.*\.,.,0.666) .666 print re.sub(.*\.,.,123.666) .666 -- http://mail.python.org/mailman/listinfo/python-list
Re: Remove integer from float number
On 2006-03-23, Arne Ludwig [EMAIL PROTECTED] wrote: With that terse description and the subject line I would interpret the OP like so: print re.sub(.*\.,.,0.666) .666 print re.sub(.*\.,.,123.666) .666 Or if you're allergic to regular expressions: print . + 0.666.split(.)[-1] .666 print . + 123.666.split(.)[-1] .666 -- Grant Edwards grante Yow! Yow! It's a hole at all the way to downtown visi.comBurbank! -- http://mail.python.org/mailman/listinfo/python-list
RE: Remove integer from float number
how about this solution: def printDecimal(number): if (number 0): print number - int(number) else: print int(number) - number -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Grant Edwards Sent: Thursday, March 23, 2006 5:11 PM To: python-list@python.org Subject: Re: Remove integer from float number On 2006-03-23, Arne Ludwig [EMAIL PROTECTED] wrote: With that terse description and the subject line I would interpret the OP like so: print re.sub(.*\.,.,0.666) .666 print re.sub(.*\.,.,123.666) .666 Or if you're allergic to regular expressions: print . + 0.666.split(.)[-1] .666 print . + 123.666.split(.)[-1] .666 -- Grant Edwards grante Yow! Yow! It's a hole at all the way to downtown visi.comBurbank! -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: Remove integer from float number
Sorry, got it backwards: def printDecimal(number): if (number = 0): print number - int(number) else: print int(number) - number -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Michael Yanowitz Sent: Thursday, March 23, 2006 5:21 PM To: python-list@python.org Subject: RE: Remove integer from float number how about this solution: def printDecimal(number): if (number 0): print number - int(number) else: print int(number) - number -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Grant Edwards Sent: Thursday, March 23, 2006 5:11 PM To: python-list@python.org Subject: Re: Remove integer from float number On 2006-03-23, Arne Ludwig [EMAIL PROTECTED] wrote: With that terse description and the subject line I would interpret the OP like so: print re.sub(.*\.,.,0.666) .666 print re.sub(.*\.,.,123.666) .666 Or if you're allergic to regular expressions: print . + 0.666.split(.)[-1] .666 print . + 123.666.split(.)[-1] .666 -- Grant Edwards grante Yow! Yow! It's a hole at all the way to downtown visi.comBurbank! -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Remove integer from float number
On 2006-03-23, Michael Yanowitz [EMAIL PROTECTED] wrote: With that terse description and the subject line I would interpret the OP like so: print re.sub(.*\.,.,0.666) .666 print re.sub(.*\.,.,123.666) .666 Or if you're allergic to regular expressions: print . + 0.666.split(.)[-1] .666 print . + 123.666.split(.)[-1] .666 how about this solution: def printDecimal(number): if (number 0): print number - int(number) else: print int(number) - number Well, for one thing it doesn't work: def printDecimal(number): ... if (number 0): ... print number - int(number) ... else: ... print int(number) - number ... printDecimal(0.666) -0.666 printDecimal(-0.666) -0.666 Secondly, it was top-posted. ;) -- Grant Edwards grante Yow! I appoint you at ambassador to Fantasy visi.comIsland!!! -- http://mail.python.org/mailman/listinfo/python-list
Re: Remove integer from float number
On 2006-03-23, Michael Yanowitz [EMAIL PROTECTED] wrote: Sorry, got it backwards: def printDecimal(number): if (number = 0): print number - int(number) else: print int(number) - number Still top posted and still doesn't work: def printDecimal(number): ... if (number = 0): ... print number - int(number) ... else: ... print int(number) - number ... printDecimal(0.666) 0.666 printDecimal(-0.666) 0.666 -- Grant Edwards grante Yow! How many retired at bricklayers from FLORIDA visi.comare out purchasing PENCIL SHARPENERS right NOW?? -- http://mail.python.org/mailman/listinfo/python-list
Re: Remove integer from float number
Michael Yanowitz [EMAIL PROTECTED] writes: Sorry, got it backwards: You also got the reply backwards (in both cases). URL:http://en.wikipedia.org/Top_posting -- \No one ever went broke underestimating the taste of the | `\American public. -- Henry L. Mencken | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Remove integer from float number
okay... out of curiousity... how would you then seperate the interger value from the fractional part do something to one side and then put it back together... like if you had 8.01 and you want to add to the '8' part in one way (ordinary decimal) and add to the .01 part modulo something .. like say modulo 12 so that adding .11 to 8.01 would give you 9.0 ... so that you had something like: . . . 7.11, 8.00, 8.01, 8.02, 8.03, 8.04, 8.05. 8.06, 8.07, 8.08, 8.09, 8.10, 8.11, 9.00 ... why you might ask? This is one way that computer's can understand musical pitch... the '.xx' part represents the pitch classes (chromatically c-b) and the integer portion represents the octave... go from b 7.11 to c (7.12 = 8.0) and likewise down from c (6.00 for example) to b 5.11 ... sometimes you want to 'pop' off the pitch-class portion of the number and do things but also keep track of your octave crossings sometimes you think why would anyone want to do that so here is why i could use such a thing.. you have sort of compound notation that has to account for the base 12 part of the problem and our octaves in regular base 10... hehe... sorry iffin i am highjacking the thread .. -k -- http://mail.python.org/mailman/listinfo/python-list