Smalltalk Rounding alogrithm

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

Smalltalk Rounding alogrithm

Postby gsharma84 » Wed May 19, 2010 1:52 am

Hi,
I wanted to know about the rounding algorithm used in Smalltalk for rounding negative float numbers like (23.35)?
thanks
gsharma84
 
Posts: 16
Joined: Mon Dec 21, 2009 8:20 pm

Re: Smalltalk Rounding alogrithm

Postby marten » Wed May 19, 2010 6:35 am

gsharma84 wrote:Hi,
I wanted to know about the rounding algorithm used in Smalltalk for rounding negative float numbers like (23.35)?
thanks


You may look at the method Number>>rounded. The first method comment says:

"Answer an Integer nearest the receiver. Basically,
the rounding follows the definition: N rounded = the
nearest integer I = N + (N sign * 0.5) in the direction
toward zero. So in the cases 0.5 rounded = 1,
-0.5 rounded = -1, 1.5 rounded = 2, -1.5 = -2 and
so on
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: No registered users and 1 guest