Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: [Help?] Integer/Decimal portion of a real number

  • To: mathgroup at
  • Subject: [mg8866] Re: [mg8847] [Help?] Integer/Decimal portion of a real number
  • From: Allan Hayes <hay at>
  • Date: Tue, 30 Sep 1997 20:16:30 -0400
  • Sender: owner-wri-mathgroup at

kammy shan leung <ksleung at>
[mg8847] [Help?] Integer/Decimal portion of a real number
> What I would like to do is break up a real number to
> its integer and decimal portion.
> For example:
>  4.12345 can be broken up to:
> integer_portion = 4
> decimal_portion = 12345


We have (slightly modifying your example)

inpt= IntegerPart[4.0012345]
frpt=FractionalPart[4.0012345 ]
But if you want to get 0012345 from the last output then one  
problem is to get the digits, which can be done) and another one is  
that 0012345 will be reduced to 12345 (which can be tackled by  
storing a list of digits or a string). For example


Strings can be converted by using the functions Characters and  

If strings are acceptable then we can move into strings right at  
the beginning and get a function

	(str = ToString[x];
		dp = StringPosition[str,"."][[1,1]];
Which gives
Note: The function RealDigits stores the information about frpt  
that we want, but problems associated with approximatig inexact  
numbers show up:


Allan Hayes
hay at
voice:+44 (0)116 2714198
fax: +44 (0)116 2718642
Leicester,  UK

  • Prev by Date: Absolute error calculation with math software
  • Next by Date: Problem/Bug w/ StackedBarChart?
  • Previous by thread: Re: [Help?] Integer/Decimal portion of a real number
  • Next by thread: Turning the elements of a list into the arguments of a function.