From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,LOTS_OF_MONEY autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b5ada130a6506d9a X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-02-20 18:29:02 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn4feed!wn3feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc52.ops.asp.att.net.POSTED!not-for-mail From: "Steve Doiel" Newsgroups: comp.lang.ada References: Subject: Re: rounding floating point numbers X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Message-ID: NNTP-Posting-Host: 12.225.227.101 X-Complaints-To: abuse@attbi.com X-Trace: rwcrnsc52.ops.asp.att.net 1014258540 12.225.227.101 (Thu, 21 Feb 2002 02:29:00 GMT) NNTP-Posting-Date: Thu, 21 Feb 2002 02:29:00 GMT Organization: AT&T Broadband Date: Thu, 21 Feb 2002 02:29:00 GMT Xref: archiver1.google.com comp.lang.ada:20192 Date: 2002-02-21T02:29:00+00:00 List-Id: "Fraz" wrote in message news:yfVc8.96077$as2.15328940@news6-win.server.ntlworld.com... > Hi > > How do i round a floating number to 2 decimal places? I know u can use > Fore, Aft, Exp in the PUT command, but i want to pass the number as > a paramater to something else, but i only want it to 2 decimal places? is > there a way to store the number like this in a variable? > > Fraz > The sample below may approximate what you're looking for: =============== Start of Sample ========================= with Ada.Float_Text_Io; with Ada.Text_Io; procedure roundto2 is a : float; begin -------------------------------------------------------------------------- -- -- Give "a" a value that has more than 2 places past the decimal -------------------------------------------------------------------------- -- a := 3.1415926; -------------------------------------------------------------------------- -- -- Display the value showing 4 places past the decimal -------------------------------------------------------------------------- -- Ada.Text_Io.Put( "Before Rounding: " ); Ada.Float_Text_Io.Put( a, 2, 4, 0 ); Ada.Text_Io.New_Line; -------------------------------------------------------------------------- -- -- Round to two places past the decimal (for practical purposes) -------------------------------------------------------------------------- -- a := float'rounding( a * 100.0 ) * 0.01; -------------------------------------------------------------------------- -- -- Display the value again showing 4 places past the decimal -------------------------------------------------------------------------- -- Ada.Text_Io.Put( "After Rounding: " ); Ada.Float_Text_Io.Put( a, 2, 4, 0 ); Ada.Text_Io.New_Line; end roundto2; ================= End of sample ======================== I hope this helps, SteveD