realbasic-nug
[Top] [All Lists]

Re: Different behavior of Str(Double)? / Re: Floating point overflow

To: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Subject: Re: Different behavior of Str(Double)? / Re: Floating point overflow
From: Norman Palardy <npalardy@great-white-software.com>
Date: Tue, 30 Sep 2008 09:07:04 -0600
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by best guess record for domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com
Delivered-to: listarchive@realsoftware.com
In-reply-to: <D8B903FF324D454BA0300ABE6555093D1757C5@BASEL.rothsoft.local>
References: <mailman.1944.1222735349.3042.realbasic-nug@lists.realsoftware.com> <D8B903FF324D454BA0300ABE6555093D1757C5@BASEL.rothsoft.local>
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com

On 30-Sep-08, at 4:14 AM, LehrerOffice - Jürg Räss wrote:

We've increased the precision to 15 significant digits to maintain
compatibility with Visual Basic, as they also display up to 15 digits of precision when using Str. Sorry that this was not documented anywhere, but
we'll definitely update our docs to reflect this change.

@William, thank you for the explanation.
We appreciate if these kind of (significant) changes are documented
in a release... then we wouldn't need to find out only when we notice
a different behavior and could find the required changes more quickly.

@Norman
If you care about how a value is presented you should use format, not STR.

Even if we care about the format in the described case, we can't use
'Format'... that's because: "Format will use the information based on the
user's locale"

So depending on the OS set up for Switzerland, Germany, Austria, ... the
reference-files would contain 1,234.45 / 1'234.45 / 1'234,45 ;-)
For us, 'Format' is the way for information shown to the user, but not
for the way it is saved (in a [text]file) for cross-country purpose.

Fortunately we already wrote a Method which does the formatting, so
we only needed to change the Str() to something else (which is a bit
more complicated now)

You can still use format

1) use format with a number like 1234.5 and find the thousands and decimal separator
        dim thousands as string
        dim decimal as string

        dim tmp as string = format(1234.5, "0,000.0")

        thousands = mid(tmp,2,1)
        decimal = mid(tmp,6,1)

 2) format the number with the precision you want
tmp = format(number,",#.0000000") // exactly 7 digits after the decimal

3) do a replace on the value so you can control precisely which numeric separators are used you have to be careful to do it in a way that you wont mess the number up though

        tmp = replaceAll(tmp,thousands,chrb(1))
        tmp = replaceAll(tmp,decimal, chrb(2))
        
        tmp = replaceAll(tmp,chrb(1),",")
        tmp = replaceAll(tmp,chrb(2),".")

or something along those lines  
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>