Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

RE: rounding

  • To: mathgroup at smc.vnet.net
  • Subject: [mg49508] RE: [mg49469] rounding
  • From: "Brown, Matt" <mbrown at phys.ksu.edu>
  • Date: Thu, 22 Jul 2004 02:45:41 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

It isn't about rounding. It's about precision. Look up precision in the Mathematica master index.
 
-----Original Message----- 
From: Amit Gandhi [mailto:akgandhi at uchicago.edu] 
To: mathgroup at smc.vnet.net
Subject: [mg49508] [mg49469] rounding





	Hello Group:
	I was wondering if anyone might be able to explain why mathematica
	does the following -
	In Mathematica I create a list of numbers as follows:
	
	mylist - Table[i, {i, 1., 8., .2}];
	
	This produces
	
	{1., 1.2, 1.4, 1.6, 1.8, 2.05, 2.2, 2.4, 2.6, 2.8, 3., 3.2, 3.4,
	3.6, 3.8, \ 4., 4.2, 4.4, 4.6, 4.8, 5., 5.2, 5.4, 5.6, 5.8, 6., 6.2,
	6.4, 6.6, 6.8, 7., \ 7.2, 7.4, 7.6, 7.8, 8.}
	
	However if I try editing this output, it shows me that the full form
	of this list is:
	
	{1.`, 1.2`, 1.4000000000000001`, 1.6`, 1.8`, 2.05`, 2.2`, 2.4`,
	2.6`, \ 2.8000000000000003`, 3.`, 3.2`, 3.4`, 3.6`,
	3.8000000000000003`, 4.`, 4.2`, \ 4.4`, 4.6000000000000005`, 4.8`,
	5.`, 5.2`, 5.4`, 5.6000000000000005`, 5.8`, \ 6.`, 6.2`, 6.4`,
	6.6000000000000005`, 6.8`, 7.`, 7.2`, 7.4`, \ 7.6000000000000005`,
	7.8`, 8.`}
	
	I would like this bottom list to be rounded so that the full form is
	equivalent to the first list. So I wrote a round function that
	rounds a real number to a specified number of decimal places:
	
	round[x_, place_] := (Round[x*(10.^place)])/(10.^place);
	
	so for instance round[3.456, 2] = 3.46.
	
	Now when I do round[mylist, 2], the full form of the numbers in the
	list continue to be
	
	{1.`, 1.2`, 1.4000000000000001`, 1.6`, 1.8`, 2.05`, 2.2`, 2.4`,
	2.6`, \ 2.8000000000000003`, 3.`, 3.2`, 3.4`, 3.6`,
	3.8000000000000003`, 4.`, 4.2`, \ 4.4`, 4.6000000000000005`, 4.8`,
	5.`, 5.2`, 5.4`, 5.6000000000000005`, 5.8`, \ 6.`, 6.2`, 6.4`,
	6.6000000000000005`, 6.8`, 7.`, 7.2`, 7.4`, \ 7.6000000000000005`,
	7.8`, 8.`}
	
	Can anyone explain to me how to properly round numbers in mathematica.
	
	


  • Prev by Date: Re: Plotting a function and its derivative
  • Next by Date: Re: Plotting a function and its derivative
  • Previous by thread: Re: Re: rounding
  • Next by thread: Plotting a function and its derivative