tag:blogger.com,1999:blog-8832291873344926372.post2775022778992395788..comments2024-03-24T14:03:17.111-04:00Comments on Cape Cod Gunny - Michael Riley: Rounding the Currency type like they taught us in schoolMichael Rileyhttp://www.blogger.com/profile/15959746627356186242noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-8832291873344926372.post-47906813329053385272012-06-11T20:18:21.318-04:002012-06-11T20:18:21.318-04:00Hi!
Maybe i have a workaround:
procedure TForm1....Hi!<br /><br />Maybe i have a workaround:<br /><br />procedure TForm1.BitBtn1Click(Sender: TObject);<br />var<br /> C: Currency;<br />begin<br /> C := 12.345;<br /> SetRoundMode(rmNearest);<br /> ShowMessage(FloatToStr(RoundTo(C, -2)));<br />end;<br /><br />Rolphy ReyesUnknownhttps://www.blogger.com/profile/13911910101088807952noreply@blogger.comtag:blogger.com,1999:blog-8832291873344926372.post-19053677090637338352012-06-11T02:21:30.433-04:002012-06-11T02:21:30.433-04:00Rounding is a nest of rattle snakes, school roundi...Rounding is a nest of rattle snakes, school rounding looks good, but is in practice not a good practice. Bankers rounding does not look good, but makes an awful lot more sense.<br />Really there, blame the school, not Delphi.<br />And Excel only "cheats" the rounding for appearances, when chaining it uses bankers rounding (leading to odd calculus vs display oddities)Erichttps://www.blogger.com/profile/05912696305224378407noreply@blogger.comtag:blogger.com,1999:blog-8832291873344926372.post-86067315779307039602012-06-10T17:12:36.059-04:002012-06-10T17:12:36.059-04:00Take a look at John Herbster's rounding routin...Take a look at John Herbster's rounding routines at http://cc.embarcadero.com/item/21909. His rounding function offers the following options as one of the parameters:<br /><br />(drNone, {No rounding.}<br /> drHalfEven,{Round to nearest or to even whole number. (a.k.a Bankers) }<br /> drHalfPos, {Round to nearest or toward positive.}<br /> drHalfNeg, {Round to nearest or toward negative.}<br /> drHalfDown,{Round to nearest or toward zero.}<br /> drHalfUp, {Round to nearest or away from zero.}<br /> drRndNeg, {Round toward negative. (a.k.a. Floor) }<br /> drRndPos, {Round toward positive. (a.k.a. Ceil ) }<br /> drRndDown, {Round toward zero. (a.k.a. Trunc) }<br /> drRndUp); {Round away from zero.}<br /><br />"Grade school" rounding would use drHalfUp. See also the Wikipedia article on rounding. It explains pros and cons of various rounding methods.<br /><br />Another old fart,<br />Max WilliamsMaxhttps://www.blogger.com/profile/09766878868542991152noreply@blogger.com