[futurebasic] Re: [FB] Print using statement

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : April 2011 : Group Archive : Group : All Groups

From: Brian S <fblistserve@...>
Date: Tue, 19 Apr 2011 07:53:32 -0700
Steve,

Formatting numbers ( with thousands separator and decimal ) is automatic if Core Foundation ( CFNumberFormatterCreate() comes to mind ) is used. You don’t have to worry about adjusting your code for each country. The FB5 demo below works for Rupiah, USD, or any country. The problem is FB4 doesn’t implement all the CF headers that are included in FB5. You would need Tlbx CFBase.incl, Tlbx CFNumber.incl, Tlbx CFLocale.incl and Tlbx CFNumberFormatter.incl at a minimum. Also FB5 headers implement new features( e.g. "system" ) and new constants( e.g. "_DEFINEDINCARBON" ) FB4 doesn’t support, so there would be work to modify those headers for use with FB4. I hope you can move to FB5. Hacking FB4’s Print Using in Subs Compiler.incl looks dubious to me and might need future changes for the "next" currency the code base doesn’t support.

'--------------------
include "Tlbx CFNumberFormatter.incl"

local fn BuildFormattedStringForDouble( cost as double ) as CFStringRef
'~'1
dim as CFLocaleRef               localeRef
dim as CFNumberFormatterRef      myFormatter
dim as CFStringRef               formattedNumberString

localeRef             = fn CFLocaleCopyCurrent
myFormatter           = fn CFNumberFormatterCreate( #0, localeRef, _kCFNumberFormatterCurrencyStyle )
formattedNumberString = fn CFNumberFormatterCreateStringWithValue( #0, myFormatter, _kCFNumberDoubleType, @cost )
CFRelease( localeRef )
CFRelease( myFormatter )
end fn = formattedNumberString

dim as double           myCost     : myCost = 123456789012.56
dim as CFStringRef      s         
dim as Str255           pascalString

s = fn BuildFormattedStringForDouble( myCost )
fn CFStringGetPascalString( s, @pascalString, 255, _kCFStringEncodingMacRoman ) // only done to use PRINT.
CFRelease( s )
print pascalString

RunApplicationEventLoop()
'--------------------

Brian S.


On Apr 19, 2011, at 7:07 AM, Steve wrote:

> I can see changing the RUNTIME to allow for printing s number in Rupiah currency would be difficult
> 
> for example :  100.000.000  = 100 million Rupiahs
> 
> The print using statement can only accept ONE decimal point.
> 
> 
> 
> On Apr 19, 2011, at 9:58 AM, Steve wrote:
> 
>> Michele,
>> 
>> thanks.  that's so obvious how did I miss it.  I was looking for the wrong thing.
>> 
>> steve
>> 
>> On Apr 19, 2011, at 9:30 AM, Michele Neri wrote:
>> 
>>> I'm sorry Steve, I was misreading (print @ instead of print using).
>>> 
>>> Look inside "Subs Compiler.Incl", RUNTIME Using.
>>> 
>>> Michele.
>>> 
>>> 
>>> 2011/4/19 Steve <mactech@...>
>>> I am using FB4.4 for this project and want to modify the PRINT USING function runtime, if possible.
>>> 
>>> On Apr 19, 2011, at 9:12 AM, Michele Neri wrote:
>>> 
>>>> (...)
>>>> 
>>>> 2011/4/19 Steve <mactech@...>
>>>> Where is the PRINT USING function defined in RUNTIME?
>>>> 
>>>> I have not been able to find it as I must be searching for the wrong thing.
>>>> 
>>> 
>>>