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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,64a2795a04707a01 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!news.glorb.com!feeder.erje.net!news.osn.de!diablo1.news.osn.de!noris.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Converting Integer / Float to String Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Thu, 17 Jul 2008 10:15:30 +0200 Message-ID: <62haf1069b85$.tb768rmm6vib.dlg@40tude.net> NNTP-Posting-Date: 17 Jul 2008 10:15:30 CEST NNTP-Posting-Host: 3079b6ca.newsspool3.arcor-online.net X-Trace: DXC=9SG`ak?5i>YV;Ef1`Jk54\McF=Q^Z^V3X4Fo<]lROoRQ8kF_MO]T^L8=7LY X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:6916 Date: 2008-07-17T10:15:30+02:00 List-Id: On Thu, 17 Jul 2008 09:49:16 +0200, Alexander Camek wrote: > is there another way to convert a given String to an Integer or Float type? Yes, there are many ways. > I am currently using some code like this: > > begin > Value :=Float'Value(Float_String); > exception > when Constraint_Error => Value := 0.0; > end; > > For me this is very ugly and a big hack. Certainly it is ugly, because it is not clear why an improperly spelt or a too large number should magically become 0.0. The first question is why do you want to convert string to float. This makes no sense in most cases. (Parsing text is not about string conversions.) The second question is about the format of the number in the string, which includes treatment of blank characters, based numbers, signed numbers and so on. The third question is about error handling, what happens upon syntax, overflow, underflow, no number, etc errors. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de