Getting fractional part from a float without using string operations

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • srinivasan srinivas

    Getting fractional part from a float without using string operations

    Thanks,
    Srini


    Add more friends to your messenger and enjoy!Go to http://messenger.yahoo.com/invite/
  • John Machin

    #2
    Re: Getting fractional part from a float without using stringoperation s

    On Nov 20, 12:35 am, srinivasan srinivas <sri_anna...@ya hoo.co.in>
    wrote:
    <null>

    | >>import math
    | >>num = 123.4567
    | >>math.modf(num )
    | (0.456699999999 99789, 123.0)

    Comment

    • MRAB

      #3
      Re: Getting fractional part from a float without using stringoperation s

      On Nov 19, 1:44 pm, John Machin <sjmac...@lexic on.netwrote:
      On Nov 20, 12:35 am, srinivasan srinivas <sri_anna...@ya hoo.co.in>
      wrote:
      <null>
      >
      | >>import math
      | >>num = 123.4567
      | >>math.modf(num )
      | (0.456699999999 99789, 123.0)
      def frac(n):
      return n - int(n)

      Comment

      • Blind Anagram

        #4
        Re: Getting fractional part from a float without using string operations

        "MRAB" <google@mrabarn ett.plus.comwro te in message
        news:278930e8-6c65-4059-9dec-713e4ba5b554@w1 g2000prk.google groups.com...
        On Nov 19, 1:44 pm, John Machin <sjmac...@lexic on.netwrote:
        On Nov 20, 12:35 am, srinivasan srinivas <sri_anna...@ya hoo.co.in>
        wrote:
        <null>
        >
        | >>import math
        | >>num = 123.4567
        | >>math.modf(num )
        | (0.456699999999 99789, 123.0)
        def frac(n):
        return n - int(n)


        n % 1.0

        Comment

        • John Machin

          #5
          Re: Getting fractional part from a float without using stringoperation s

          On Nov 20, 3:38 am, "Blind Anagram" <nob...@nowhere .orgwrote:
          "MRAB" <goo...@mrabarn ett.plus.comwro te in message
          >
          news:278930e8-6c65-4059-9dec-713e4ba5b554@w1 g2000prk.google groups.com...
          On Nov 19, 1:44 pm, John Machin <sjmac...@lexic on.netwrote:
          >
          On Nov 20, 12:35 am, srinivasan srinivas <sri_anna...@ya hoo.co.in>
          wrote:
          <null>
          >
          | >>import math
          | >>num = 123.4567
          | >>math.modf(num )
          | (0.456699999999 99789, 123.0)
          >
          def frac(n):
              return n - int(n)
          >
          n % 1.0
          | >>n= -123.4567
          | >>n % 1.0
          | 0.5433000000000 0211

          Comment

          Working...