comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Converting Integer / Float to String
Date: Thu, 17 Jul 2008 10:15:30 +0200
Date: 2008-07-17T10:15:30+02:00	[thread overview]
Message-ID: <62haf1069b85$.tb768rmm6vib.dlg@40tude.net> (raw)
In-Reply-To: newscache$sc454k$rp5$1@pleione.3soft.de

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



  parent reply	other threads:[~2008-07-17  8:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-17  7:49 Converting Integer / Float to String Alexander Camek
2008-07-17  8:05 ` anon
2008-07-17  8:15 ` Dmitry A. Kazakov [this message]
2008-07-17  8:32   ` Alexander Camek
2008-07-17  9:24     ` Dmitry A. Kazakov
2008-07-20  0:28 ` JPWoodruff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox