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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.182.226.163 with SMTP id rt3mr1110423obc.13.1399383073642; Tue, 06 May 2014 06:31:13 -0700 (PDT) X-Received: by 10.140.91.40 with SMTP id y37mr36188qgd.37.1399383073601; Tue, 06 May 2014 06:31:13 -0700 (PDT) Path: border2.nntp.dca3.giganews.com!backlog4.nntp.dca3.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!c1no2051491igq.0!news-out.google.com!dz10ni33449qab.1!nntp.google.com!ih12no834341qab.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 6 May 2014 06:31:13 -0700 (PDT) In-Reply-To: <9ac10bab-2ade-4ac8-a99b-336595e38f67@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=57.79.21.1; posting-account=gRqrnQkAAAAC_02ynnhqGk1VRQlve6ZG NNTP-Posting-Host: 57.79.21.1 References: <9ac10bab-2ade-4ac8-a99b-336595e38f67@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Noob question.. Autopromotion? From: gautier_niouzes@hotmail.com Injection-Date: Tue, 06 May 2014 13:31:13 +0000 Content-Type: text/plain; charset=ISO-8859-1 X-Original-Bytes: 2675 Xref: number.nntp.dca.giganews.com comp.lang.ada:186267 Date: 2014-05-06T06:31:13-07:00 List-Id: Hello, As Adam said, a figure read as a literal in the Ada source code and a figure read from a string from an user are different topics. Typically figures with or without .0 are valid (to GNAT and OA run-time libraries at least). with ada.text_io; procedure value is begin ada.text_io.put_line(float'image(float'Value("1234.0"))); ada.text_io.put_line(float'image(float'Value("1234"))); end; Now, you may have user inputs with thousands separators and/or percents, for instance - especially if the input is actually a slight modification of an output). So you will certainly need a custom solution anyway. Here is a function dealing with both (filtering thousands separators, and doing *0.01 with percent signs): function Value(s: String) return Real is t: constant String:= Trim(s, Both); ft: String(t'Range); j: Integer; begin if t'Length > 0 and then t(t'Last) = '%' then return Value(t(t'First .. t'Last-1)) * 0.01; elsif Index(t, (1 => thousands_separator)) = 0 then return Real'Value(t); else -- filter all thousands separators... j:= ft'First - 1; for i in t'Range loop if t(i) /= thousands_separator then j:= j + 1; ft(j):= t(i); end if; end loop; return Value(ft(ft'First .. j)); end if; end Value; _________________________ Gautier's Ada programming http://gautiersblog.blogspot.com/search/label/Ada NB: follow the above link for a valid e-mail address