473,386 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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/
Nov 19 '08 #1
4 16935
On Nov 20, 12:35*am, srinivasan srinivas <sri_anna...@yahoo.co.in>
wrote:
<null>

| >>import math
| >>num = 123.4567
| >>math.modf(num)
| (0.45669999999999789, 123.0)
Nov 19 '08 #2
On Nov 19, 1:44*pm, John Machin <sjmac...@lexicon.netwrote:
On Nov 20, 12:35*am, srinivasan srinivas <sri_anna...@yahoo.co.in>
wrote:
<null>

| >>import math
| >>num = 123.4567
| >>math.modf(num)
| (0.45669999999999789, 123.0)
def frac(n):
return n - int(n)
Nov 19 '08 #3
"MRAB" <go****@mrabarnett.plus.comwrote in message
news:27**********************************@w1g2000p rk.googlegroups.com...
On Nov 19, 1:44 pm, John Machin <sjmac...@lexicon.netwrote:
On Nov 20, 12:35 am, srinivasan srinivas <sri_anna...@yahoo.co.in>
wrote:
<null>

| >>import math
| >>num = 123.4567
| >>math.modf(num)
| (0.45669999999999789, 123.0)
def frac(n):
return n - int(n)
n % 1.0

Nov 19 '08 #4
On Nov 20, 3:38*am, "Blind Anagram" <nob...@nowhere.orgwrote:
"MRAB" <goo...@mrabarnett.plus.comwrote in message

news:27**********************************@w1g2000p rk.googlegroups.com...
On Nov 19, 1:44 pm, John Machin <sjmac...@lexicon.netwrote:
On Nov 20, 12:35 am, srinivasan srinivas <sri_anna...@yahoo.co.in>
wrote:
<null>
| >>import math
| >>num = 123.4567
| >>math.modf(num)
| (0.45669999999999789, 123.0)

def frac(n):
* * return n - int(n)

n % 1.0
| >>n= -123.4567
| >>n % 1.0
| 0.54330000000000211
Nov 19 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
13
by: maadhuu | last post by:
hello , i would like to know as to why double is more efficient than float . thanking you, ranjan.
5
by: Michael Søndergaard | last post by:
I Pascal there are a function for retriving the fractional part of a real number (Frac), I can't find any in the dotnet framework. The function needs to remove the integer part and keep only the...
5
by: ME | last post by:
What is the fastest way of getting the fraction part of a floating point number? So, if I have a float 10.3 I want to get a float with value 0.3 fast. Thanks
60
by: Erick-> | last post by:
hi all... I've readed some lines about the difference between float and double data types... but, in the real world, which is the best? when should we use float or double?? thanks Erick
2
by: djzbor | last post by:
Any who can help!! let i have a number 16.0230045 i want to count the fractional part of this number means i want to get the number of digits of the fractional part of this number and store each...
2
by: Bob | last post by:
Greetings All, Is there a simple way of suppressing the fractional part of a timespan At the moment I use one time span to populate another minus the fractional part .. this is a bit clunky. ...
10
by: schaefer.mp | last post by:
Does anyone know of an approximation to raising a negative base to a fractional exponent? For example, (-3)^-4.11111 since this cannot be computed without using imaginary numbers. Any help is...
12
by: bsabiston | last post by:
Hi, I'm trying to get the fractional part of a floating point number. I've tried fmod() and modf(), and while both do work, they also occasionally return 1.0 for the fractional part of the number...
0
by: Chris Rebert | last post by:
On Wed, Nov 19, 2008 at 10:01 PM, srinivasan srinivas <sri_annauni@yahoo.co.inwrote: Since you really care about significant figures here, have you considered using decimal rather than float as,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.