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.6 required=5.0 tests=BAYES_00,FROM_WORDY 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: g2news1.google.com!news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!news.albasani.net!newsfeed.straub-nv.de!noris.net!not-for-mail From: "Alexander Camek" Newsgroups: comp.lang.ada Subject: Re: Converting Integer / Float to String Date: Thu, 17 Jul 2008 10:32:59 +0200 Message-ID: References: <62haf1069b85$.tb768rmm6vib.dlg@40tude.net> NNTP-Posting-Host: pleione.3soft.de X-Trace: ork-un.noris.net 1216283546 17111 213.95.68.8 (17 Jul 2008 08:32:26 GMT) X-Complaints-To: news@noris.net NNTP-Posting-Date: Thu, 17 Jul 2008 08:32:26 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5512 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512 X-NNTP-Posting-Host: www9.backup.noris.net Xref: g2news1.google.com comp.lang.ada:1189 Date: 2008-07-17T10:32:59+02:00 List-Id: Hi Dimitry, "Dmitry A. Kazakov" wrote in message news:62haf1069b85$.tb768rmm6vib.dlg@40tude.net... > On Thu, 17 Jul 2008 09:49:16 +0200, Alexander Camek wrote: >> 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. First of all, this was only a base to start discussion on it and at that point I need some value to initial my float or integer value to get a proper value if the string is malformed. As far as I can tell, the background of the code snipplet is that the string is given from an xml file which is parsed by glib xml and there I get all as a string. To your second question. The whitespaces are trimmed and I can only rely on the point that there is a correct value in it, if not then the default value will be set or at the beginning for initilisation 0.0 is used. To your third question. That is reason why I posted here. I want to get a idea what I have missed in doing my parsing or how to do it a better way. It is clear that there is no silver bullet to do that. But what I want is a good feeling about how to deal with it, what I have to think about and how to deal with it. Greetings Alexander