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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,91965a012526b259 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Nick Roberts Newsgroups: comp.lang.ada Subject: Re: Float to String Date: Mon, 08 Nov 2004 21:29:35 +0000 Message-ID: <2va6q0F2gvpugU1@uni-berlin.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de IJkmNI/OdXr33yPVQy4eVAJT6B5rFY4KEIu+Wh752TGSNuaqs= User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040803 X-Accept-Language: en-us, en In-Reply-To: Xref: g2news1.google.com comp.lang.ada:6056 Date: 2004-11-08T21:29:35+00:00 List-Id: Pascal Obry wrote: > I was wondering if there is a way to save a float into a string and read it > back without loosing precision ? > > I tried something like: > > F_Str : String (1 .. Float'Base'Digits); > > Float_Text_IO.Put (F_Str, My_Float, Aft => Float'Base'Digits); > > But this is not enough... Ideas ? If it is not necessary for the string to be human interpretable, you could take the approach: use streaming to convert the floating point value into a Storage_Element_Array; write out the array as a sequence of hexadecimal values into the string. Obviously you do the reverse to convert back to floating point values. -- Nick Roberts