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
.



Relevant Pages

  • Re: Remove integer from float number
    ... On 24/03/2006 6:44 AM, Larry Bates wrote: ... from float: ... Derek Basch ... I'm sure of neither what the OP is trying to accomplish nor what Larry's ...
    (comp.lang.python)
  • Re: Newby: More VC6 errors...
    ... I am trying to typecast an int and a float into a basic_string. ... The help files are less than helpful. ... How do I accomplish this? ...
    (microsoft.public.vc.language)
  • Re: "Shifting" floating point numbers
    ... powers of two? ... mantissa. ... But can I write C code to accomplish this ... the float variable. ...
    (comp.lang.c)
  • Newby: More VC6 errors...
    ... I am trying to typecast an int and a float into a basic_string. ... The help files are less than helpful. ... How do I accomplish this? ... The trouble is I haven't touched C/C++ in 10 years. ...
    (microsoft.public.vc.language)
  • Calculating EigenValues with CLAPACK
    ... eigenvalues with CLAPACK? ... I have tried a simple C code to accomplish this for a 4x4 symmetric ... float d; ...
    (sci.math.num-analysis)