Formatting monetary amounts and percentages

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
20 messages Options
Reply | Threaded
Open this post in threaded view
|

Formatting monetary amounts and percentages

Rick Flower
Hi all..

It seems to me that I may have asked this before, but couldn't find my
notes (and didn't seem to find anything in a few of my online PDF
Smalltalk books I had lying around).. Anyway, I've got some monetary
amounts expressed as fixed point integers and also some percentages
expressed the same way (e.g. 4% is 4s).. Anyway, I'd like to format
these numbers as typical money amounts or percentages respectively..
I was playing around with some of the built-in functions for integers
to try to specify my own formatting but just don't know what needs to be
specified to get my desired output..  I tried the following but it
doesn't get the right set of digits in the output for things like $25.00

moneyValue := '$', (fixedValue asFloat asString)

Sample input/outputs:
fixedValue = 25s.
moneyValue = '$25.0'

Any suggestions would be greatly appreciated!

Thanks!

Reply | Threaded
Open this post in threaded view
|

Re: Formatting monetary amounts and percentages

Joseph Bacanskas-4
Hi Rick:


On Feb 4, 2007, at 7:37 PM, Rick Flower wrote:

> Hi all..
>
> It seems to me that I may have asked this before, but couldn't find  
> my notes (and didn't seem to find anything in a few of my online  
> PDF Smalltalk books I had lying around).. Anyway, I've got some  
> monetary amounts expressed as fixed point integers and also some  
> percentages expressed the same way (e.g. 4% is 4s).. Anyway, I'd  
> like to format these numbers as typical money amounts or  
> percentages respectively..
> I was playing around with some of the built-in functions for integers
> to try to specify my own formatting but just don't know what needs  
> to be specified to get my desired output..  I tried the following  
> but it doesn't get the right set of digits in the output for things  
> like $25.00
>
> moneyValue := '$', (fixedValue asFloat asString)
>
> Sample input/outputs:
> fixedValue = 25s.
> moneyValue = '$25.0'
>
> Any suggestions would be greatly appreciated!
>
> Thanks!
>

I work with GemStone almost exclusively.  But looking quickly in a VW  
image lead me to this quick hack...

(25 asFixedPoint: 2) printString copyWithout: $s

That will give you the '25.00'.

It is usually a prudent idea to avoid using floats for money  
representation, though you seem to be limiting the useage to string  
creation in your example.

Thanks!!
Joseph Bacanskas [|]
--- I use Smalltalk.  My amp goes to eleven.

Reply | Threaded
Open this post in threaded view
|

RE: Formatting monetary amounts and percentages

Boris Popov, DeepCove Labs (SNN)
Re: Formatting monetary amounts and percentages
NumberPrintPolicy print: 25.46s2 using: '$#,###.00;($#,###.00);0.00'
 
or
 
TimestampPrintPolicy print: Timestamp now using: 'yyyy-mmm-dd hh:mm:ss.fff'
 
We also have #printUsing: extensions, so you could these as,
 
25.46s2 printUsing: '$#,###.00;($#,###.00);0.00'
 
or
 
Timestamp now printUsing: 'yyyy-mmm-dd hh:mm:ss.fff'
 
Hope this helps,
 
-Boris

--
+1.604.689.0322
DeepCove Labs Ltd.
4th floor 595 Howe Street
Vancouver, Canada V6C 2T5

[hidden email]

CONFIDENTIALITY NOTICE

This email is intended only for the persons named in the message
header. Unless otherwise indicated, it contains information that is
private and confidential. If you have received it in error, please
notify the sender and delete the entire message including any
attachments.

Thank you.


From: Joseph Bacanskas [mailto:[hidden email]]
Sent: Sun 04/02/2007 9:22 PM
To: Visualworks Mailing List
Cc: Rick Flower
Subject: Re: Formatting monetary amounts and percentages

Hi Rick:


On Feb 4, 2007, at 7:37 PM, Rick Flower wrote:


> Hi all..
>
> It seems to me that I may have asked this before, but couldn't find 
> my notes (and didn't seem to find anything in a few of my online 
> PDF Smalltalk books I had lying around).. Anyway, I've got some 
> monetary amounts expressed as fixed point integers and also some 
> percentages expressed the same way (e.g. 4% is 4s).. Anyway, I'd 
> like to format these numbers as typical money amounts or 
> percentages respectively..
> I was playing around with some of the built-in functions for integers
> to try to specify my own formatting but just don't know what needs 
> to be specified to get my desired output..  I tried the following 
> but it doesn't get the right set of digits in the output for things 
> like $25.00
>
> moneyValue := '$', (fixedValue asFloat asString)
>
> Sample input/outputs:
> fixedValue = 25s.
> moneyValue = '$25.0'
>
> Any suggestions would be greatly appreciated!
>
> Thanks!
>

I work with GemStone almost exclusively.  But looking quickly in a VW 
image lead me to this quick hack...

(25 asFixedPoint: 2) printString copyWithout: $s

That will give you the '25.00'.

It is usually a prudent idea to avoid using floats for money 
representation, though you seem to be limiting the useage to string 
creation in your example.

Thanks!!
Joseph Bacanskas [|]
--- I use Smalltalk.  My amp goes to eleven.

Reply | Threaded
Open this post in threaded view
|

Re: Formatting monetary amounts and percentages

Rick Flower
In reply to this post by Joseph Bacanskas-4
Joseph Bacanskas wrote:

> Hi Rick:
>
>
> On Feb 4, 2007, at 7:37 PM, Rick Flower wrote:
>
>> Hi all..
>>
>> It seems to me that I may have asked this before, but couldn't find
>> my notes (and didn't seem to find anything in a few of my online PDF
>> Smalltalk books I had lying around).. Anyway, I've got some monetary
>> amounts expressed as fixed point integers and also some percentages
>> expressed the same way (e.g. 4% is 4s).. Anyway, I'd like to format
>> these numbers as typical money amounts or percentages respectively..
>> I was playing around with some of the built-in functions for integers
>> to try to specify my own formatting but just don't know what needs to
>> be specified to get my desired output..  I tried the following but it
>> doesn't get the right set of digits in the output for things like $25.00
>>
>> moneyValue := '$', (fixedValue asFloat asString)
>>
>> Sample input/outputs:
>> fixedValue = 25s.
>> moneyValue = '$25.0'
>>
>> Any suggestions would be greatly appreciated!
>>
>> Thanks!
>>
>
> I work with GemStone almost exclusively.  But looking quickly in a VW
> image lead me to this quick hack...
>
> (25 asFixedPoint: 2) printString copyWithout: $s
>
> That will give you the '25.00'.
>
> It is usually a prudent idea to avoid using floats for money
> representation, though you seem to be limiting the useage to string
> creation in your example.
>
Thanks.. In this case the end result will be used as part of a Seaside
based web-app -- only for display purposes.. I had pondered with the
idea of chopping off the "s" on the end of the string but figured there
might be a cleaner way..  Your way seems to work fine.. Thanks again!

Reply | Threaded
Open this post in threaded view
|

Re: Formatting monetary amounts and percentages

Rick Flower
In reply to this post by Boris Popov, DeepCove Labs (SNN)
Boris Popov wrote:

> NumberPrintPolicy print: 25.46s2 using: '$#,###.00;($#,###.00);0.00'
>  
> or
>  
> TimestampPrintPolicy print: Timestamp now using: 'yyyy-mmm-dd
> hh:mm:ss.fff'
>  
> We also have #printUsing: extensions, so you could these as,
>  
> 25.46s2 printUsing: '$#,###.00;($#,###.00);0.00'
>  
> or
>  
> Timestamp now printUsing: 'yyyy-mmm-dd hh:mm:ss.fff'
Thanks Boris --

Are the #printUsing: extensions part of something I need to load in?
I got an error when I tried using it.. The first one worked OK though
so I'll probably fiddle with that some more.. Thanks all for the quick
replies!

Reply | Threaded
Open this post in threaded view
|

Re: Formatting monetary amounts and percentages

Boris Popov, DeepCove Labs (SNN)
In reply to this post by Rick Flower
Re: Formatting monetary amounts and percentages

Oh yea its just a shortcut that we use without remembering the class names for things like numbers and dates etc. By default the first two will do you just fine, we use it all the time to implement printing policies, formats and such, includind on seaside.

Cheers!

-Boris
(Sent from a BlackBerry)

----- Original Message -----
From: Rick Flower <[hidden email]>
To: Boris Popov
Cc: Joseph Bacanskas <[hidden email]>; Visualworks Mailing List <[hidden email]>
Sent: Sun Feb 04 21:50:12 2007
Subject: Re: Formatting monetary amounts and percentages

Boris Popov wrote:
> NumberPrintPolicy print: 25.46s2 using: '$#,###.00;($#,###.00);0.00'

> or

> TimestampPrintPolicy print: Timestamp now using: 'yyyy-mmm-dd
> hh:mm:ss.fff'

> We also have #printUsing: extensions, so you could these as,

> 25.46s2 printUsing: '$#,###.00;($#,###.00);0.00'

> or

> Timestamp now printUsing: 'yyyy-mmm-dd hh:mm:ss.fff'
Thanks Boris --

Are the #printUsing: extensions part of something I need to load in?
I got an error when I tried using it.. The first one worked OK though
so I'll probably fiddle with that some more.. Thanks all for the quick
replies!

Reply | Threaded
Open this post in threaded view
|

RE: Formatting monetary amounts and percentages

Boris Popov, DeepCove Labs (SNN)
Re: Formatting monetary amounts and percentages
NumberPrintPolicy print: 0.42 using: '#,###.00%;(#,###.00%);0.00%'
 
Also, see comments on various PrintPolicy subclasses for details on all the tokens,
 
Cheers!
 
-Boris

--
+1.604.689.0322
DeepCove Labs Ltd.
4th floor 595 Howe Street
Vancouver, Canada V6C 2T5

[hidden email]

CONFIDENTIALITY NOTICE

This email is intended only for the persons named in the message
header. Unless otherwise indicated, it contains information that is
private and confidential. If you have received it in error, please
notify the sender and delete the entire message including any
attachments.

Thank you.


From: Rick Flower [mailto:[hidden email]]
Sent: Sun 04/02/2007 10:01 PM
To: Boris Popov
Subject: Re: Formatting monetary amounts and percentages

Thanks Boris --

One quick question -- If I want to create a string such as 4.75% using
your formatting, I've got the number but can't get the % put in -- Is
that just a case of properly escaping it?  I tried using % and %% -- I
know how to do that in C/C++ but not in ST.. Anyway, just thought I'd
ask... Thanks!

Boris Popov wrote:


>
> Oh yea its just a shortcut that we use without remembering the class
> names for things like numbers and dates etc. By default the first two
> will do you just fine, we use it all the time to implement printing
> policies, formats and such, includind on seaside.
>
> Cheers!
>
> -Boris
> (Sent from a BlackBerry)
>
> ----- Original Message -----
> From: Rick Flower <[hidden email]>
> To: Boris Popov
> Cc: Joseph Bacanskas <[hidden email]>; Visualworks Mailing
> List <[hidden email]>
> Sent: Sun Feb 04 21:50:12 2007
> Subject: Re: Formatting monetary amounts and percentages
>
> Boris Popov wrote:
> > NumberPrintPolicy print: 25.46s2 using: '$#,###.00;($#,###.00);0.00'
> >
> > or
> >
> > TimestampPrintPolicy print: Timestamp now using: 'yyyy-mmm-dd
> > hh:mm:ss.fff'
> >
> > We also have #printUsing: extensions, so you could these as,
> >
> > 25.46s2 printUsing: '$#,###.00;($#,###.00);0.00'
> >
> > or
> >
> > Timestamp now printUsing: 'yyyy-mmm-dd hh:mm:ss.fff'
> Thanks Boris --
>
> Are the #printUsing: extensions part of something I need to load in?
> I got an error when I tried using it.. The first one worked OK though
> so I'll probably fiddle with that some more.. Thanks all for the quick
> replies!
>

Reply | Threaded
Open this post in threaded view
|

Re: Formatting monetary amounts and percentages

Rick Flower
Thanks again Boris -- I wouldn't have thought to look in the
Internationalization section -- I was looking in the core VW classes..
I'll read the docs that are part of the code.. Thanks again!

Boris Popov wrote:

> NumberPrintPolicy print: 0.42 using: '#,###.00%;(#,###.00%);0.00%'
>  
> Also, see comments on various PrintPolicy subclasses for details on
> all the tokens,
>  
> Cheers!
>  
> -Boris
>
> --
> +1.604.689.0322
> DeepCove Labs Ltd.
> 4th floor 595 Howe Street
> Vancouver, Canada V6C 2T5
>
> [hidden email]
>
> CONFIDENTIALITY NOTICE
>
> This email is intended only for the persons named in the message
> header. Unless otherwise indicated, it contains information that is
> private and confidential. If you have received it in error, please
> notify the sender and delete the entire message including any
> attachments.
>
> Thank you.
>
> ------------------------------------------------------------------------
> *From:* Rick Flower [mailto:[hidden email]]
> *Sent:* Sun 04/02/2007 10:01 PM
> *To:* Boris Popov
> *Subject:* Re: Formatting monetary amounts and percentages
>
> Thanks Boris --
>
> One quick question -- If I want to create a string such as 4.75% using
> your formatting, I've got the number but can't get the % put in -- Is
> that just a case of properly escaping it?  I tried using % and %% -- I
> know how to do that in C/C++ but not in ST.. Anyway, just thought I'd
> ask... Thanks!
>
> Boris Popov wrote:
> >
> > Oh yea its just a shortcut that we use without remembering the class
> > names for things like numbers and dates etc. By default the first two
> > will do you just fine, we use it all the time to implement printing
> > policies, formats and such, includind on seaside.
> >
> > Cheers!
> >
> > -Boris
> > (Sent from a BlackBerry)
> >
> > ----- Original Message -----
> > From: Rick Flower <[hidden email]>
> > To: Boris Popov
> > Cc: Joseph Bacanskas <[hidden email]>; Visualworks Mailing
> > List <[hidden email]>
> > Sent: Sun Feb 04 21:50:12 2007
> > Subject: Re: Formatting monetary amounts and percentages
> >
> > Boris Popov wrote:
> > > NumberPrintPolicy print: 25.46s2 using: '$#,###.00;($#,###.00);0.00'
> > >
> > > or
> > >
> > > TimestampPrintPolicy print: Timestamp now using: 'yyyy-mmm-dd
> > > hh:mm:ss.fff'
> > >
> > > We also have #printUsing: extensions, so you could these as,
> > >
> > > 25.46s2 printUsing: '$#,###.00;($#,###.00);0.00'
> > >
> > > or
> > >
> > > Timestamp now printUsing: 'yyyy-mmm-dd hh:mm:ss.fff'
> > Thanks Boris --
> >
> > Are the #printUsing: extensions part of something I need to load in?
> > I got an error when I tried using it.. The first one worked OK though
> > so I'll probably fiddle with that some more.. Thanks all for the quick
> > replies!
> >
>

Reply | Threaded
Open this post in threaded view
|

Re: Formatting monetary amounts and percentages

Thomas Gagné-2
In reply to this post by Rick Flower
We use:

 (Locale current printAsCurrency: 1234.56s) asString

--
Visit <http://tggagne.blogspot.com/>,<http://gagne.homedns.org/> or
      <http://gagne.homedns.org/~tgagne/> for more great reading.

Reply | Threaded
Open this post in threaded view
|

RE: Formatting monetary amounts and percentages

Boris Popov, DeepCove Labs (SNN)
What about currencies that aren't 2 minor units? There's just not enough metadata about what you're trying to print if it's just a number :)

-Boris

--
+1.604.689.0322
DeepCove Labs Ltd.
4th floor 595 Howe Street
Vancouver, Canada V6C 2T5
http://tinyurl.com/r7uw4

[hidden email]

CONFIDENTIALITY NOTICE

This email is intended only for the persons named in the message
header. Unless otherwise indicated, it contains information that is
private and confidential. If you have received it in error, please
notify the sender and delete the entire message including any
attachments.

Thank you.

-----Original Message-----
From: Thomas Gagné [mailto:[hidden email]]
Sent: Monday, February 05, 2007 7:59 AM
To: vwnc
Subject: Re: Formatting monetary amounts and percentages

We use:

 (Locale current printAsCurrency: 1234.56s) asString

--
Visit <http://tggagne.blogspot.com/>,<http://gagne.homedns.org/> or
      <http://gagne.homedns.org/~tgagne/> for more great reading.

Reply | Threaded
Open this post in threaded view
|

Re: Formatting monetary amounts and percentages

Thomas Gagné-2
Wouldn't that be accommodated in the local currency policy?  Can you
give an example?  I haven't used international currencies.

Boris Popov wrote:
> What about currencies that aren't 2 minor units? There's just not enough metadata about what you're trying to print if it's just a number :)
>
> -Boris
>
>  

--
Visit <http://tggagne.blogspot.com/>,<http://gagne.homedns.org/> or
      <http://gagne.homedns.org/~tgagne/> for more great reading.

Reply | Threaded
Open this post in threaded view
|

RE: Formatting monetary amounts and percentages

Boris Popov, DeepCove Labs (SNN)
Just a quirk of multi-currency systems: 100 JPY is printed as "100" versus 100 CAD which is printed as "100.00", in other words your current locale has more to do with placement of commas and periods whereas currency itself usually defines number of minor units to go with it,

Cheers!

-Boris

--
+1.604.689.0322
DeepCove Labs Ltd.
4th floor 595 Howe Street
Vancouver, Canada V6C 2T5
http://tinyurl.com/r7uw4

[hidden email]

CONFIDENTIALITY NOTICE

This email is intended only for the persons named in the message
header. Unless otherwise indicated, it contains information that is
private and confidential. If you have received it in error, please
notify the sender and delete the entire message including any
attachments.

Thank you.

-----Original Message-----
From: Thomas Gagné [mailto:[hidden email]]
Sent: Monday, February 05, 2007 10:31 AM
To: vwnc
Subject: Re: Formatting monetary amounts and percentages

Wouldn't that be accommodated in the local currency policy?  Can you
give an example?  I haven't used international currencies.

Boris Popov wrote:
> What about currencies that aren't 2 minor units? There's just not enough metadata about what you're trying to print if it's just a number :)
>
> -Boris
>
>  

--
Visit <http://tggagne.blogspot.com/>,<http://gagne.homedns.org/> or
      <http://gagne.homedns.org/~tgagne/> for more great reading.

Reply | Threaded
Open this post in threaded view
|

Re: Formatting monetary amounts and percentages

davidbuck
In reply to this post by Thomas Gagné-2
The Dinars from Iraq, Iran and other countries in that area uses 3
decimal places of accuracy.

David Buck


Thomas Gagné wrote:

> Wouldn't that be accommodated in the local currency policy?  Can you
> give an example?  I haven't used international currencies.
>
> Boris Popov wrote:
>
>> What about currencies that aren't 2 minor units? There's just not
>> enough metadata about what you're trying to print if it's just a
>> number :)
>>
>> -Boris
>>
>>  
>
>

Reply | Threaded
Open this post in threaded view
|

RE: Formatting monetary amounts and percentages

Boris Popov, DeepCove Labs (SNN)
Yup, same thing; basically goes to show that Locale only knows how to print a local currency, responsibility for printing other currencies lies outside of it.

-Boris

--
+1.604.689.0322
DeepCove Labs Ltd.
4th floor 595 Howe Street
Vancouver, Canada V6C 2T5
http://tinyurl.com/r7uw4

[hidden email]

CONFIDENTIALITY NOTICE

This email is intended only for the persons named in the message
header. Unless otherwise indicated, it contains information that is
private and confidential. If you have received it in error, please
notify the sender and delete the entire message including any
attachments.

Thank you.

-----Original Message-----
From: David Buck [mailto:[hidden email]]
Sent: Monday, February 05, 2007 11:04 AM
To: Thomas Gagné
Cc: vwnc
Subject: Re: Formatting monetary amounts and percentages

The Dinars from Iraq, Iran and other countries in that area uses 3
decimal places of accuracy.

David Buck


Thomas Gagné wrote:

> Wouldn't that be accommodated in the local currency policy?  Can you
> give an example?  I haven't used international currencies.
>
> Boris Popov wrote:
>
>> What about currencies that aren't 2 minor units? There's just not
>> enough metadata about what you're trying to print if it's just a
>> number :)
>>
>> -Boris
>>
>>  
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Formatting monetary amounts and percentages

Dave Stevenson-2
In reply to this post by Rick Flower
You've gotten lots of feedback on formatting and printing. However, what
does not make sense to me from your original post is why you would
represent a currency with precision zero? Instead of 25s, why aren't you
using 25.00s for all currencies?

And 4s is 400%, not 4%, so I would use 0.04s for this one.

Dave

Rick Flower wrote:

> Hi all..
>
> It seems to me that I may have asked this before, but couldn't find my
> notes (and didn't seem to find anything in a few of my online PDF
> Smalltalk books I had lying around).. Anyway, I've got some monetary
> amounts expressed as fixed point integers and also some percentages
> expressed the same way (e.g. 4% is 4s).. Anyway, I'd like to format
> these numbers as typical money amounts or percentages respectively..
> I was playing around with some of the built-in functions for integers
> to try to specify my own formatting but just don't know what needs to be
> specified to get my desired output..  I tried the following but it
> doesn't get the right set of digits in the output for things like $25.00
>
> moneyValue := '$', (fixedValue asFloat asString)
>
> Sample input/outputs:
> fixedValue = 25s.
> moneyValue = '$25.0'
>
> Any suggestions would be greatly appreciated!
>
> Thanks!
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Formatting monetary amounts and percentages

Rick Flower
Dave --

Good questions.. I've got my data coming out of a database and it
populates some of my ST objects with various items including some
percentages, etc.. My percentages in the database are expressed as "4.2"
if the value is 4.2% instead of 0.42.. I need to revisit Postgres to
make sure that's the best way to store that data (and certainly OT for
this list).. All of my code is a work-in-progress and needs further
refinement and I'm currently going through all of that code to make sure
things are behaving well.. I chose not to use floats for the obvious
imprecise reasons that I'm sure you're aware of.. I just need to make
sure that the translation between the database data and my ST objects is
correct and functioning..  Thanks for bringing up these items as I'll be
looking at them further..

-- Rick

Dave Stevenson wrote:

> You've gotten lots of feedback on formatting and printing. However, what
> does not make sense to me from your original post is why you would
> represent a currency with precision zero? Instead of 25s, why aren't you
> using 25.00s for all currencies?
>
> And 4s is 400%, not 4%, so I would use 0.04s for this one.
>
> Dave
>
> Rick Flower wrote:
>> Hi all..
>>
>> It seems to me that I may have asked this before, but couldn't find my
>> notes (and didn't seem to find anything in a few of my online PDF
>> Smalltalk books I had lying around).. Anyway, I've got some monetary
>> amounts expressed as fixed point integers and also some percentages
>> expressed the same way (e.g. 4% is 4s).. Anyway, I'd like to format
>> these numbers as typical money amounts or percentages respectively..
>> I was playing around with some of the built-in functions for integers
>> to try to specify my own formatting but just don't know what needs to
>> be specified to get my desired output..  I tried the following but it
>> doesn't get the right set of digits in the output for things like $25.00
>>
>> moneyValue := '$', (fixedValue asFloat asString)
>>
>> Sample input/outputs:
>> fixedValue = 25s.
>> moneyValue = '$25.0'
>>
>> Any suggestions would be greatly appreciated!
>>
>> Thanks!
>>
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: Formatting monetary amounts and percentages

Dave Stevenson-2
If I understand correctly, you want to avoid storing a float in the db
to represent aFixedPoint in the domain? I'm not the guy to ask about db
stuff, but I have a vague feeling that there is a proper way to do this.

Dave

Rick Flower wrote:

> Dave --
>
> Good questions.. I've got my data coming out of a database and it
> populates some of my ST objects with various items including some
> percentages, etc.. My percentages in the database are expressed as "4.2"
> if the value is 4.2% instead of 0.42.. I need to revisit Postgres to
> make sure that's the best way to store that data (and certainly OT for
> this list).. All of my code is a work-in-progress and needs further
> refinement and I'm currently going through all of that code to make sure
> things are behaving well.. I chose not to use floats for the obvious
> imprecise reasons that I'm sure you're aware of.. I just need to make
> sure that the translation between the database data and my ST objects is
> correct and functioning..  Thanks for bringing up these items as I'll be
> looking at them further..
>
> -- Rick
>
> Dave Stevenson wrote:
>> You've gotten lots of feedback on formatting and printing. However,
>> what does not make sense to me from your original post is why you
>> would represent a currency with precision zero? Instead of 25s, why
>> aren't you using 25.00s for all currencies?
>>
>> And 4s is 400%, not 4%, so I would use 0.04s for this one.
>>
>> Dave
>>
>> Rick Flower wrote:
>>> Hi all..
>>>
>>> It seems to me that I may have asked this before, but couldn't find
>>> my notes (and didn't seem to find anything in a few of my online PDF
>>> Smalltalk books I had lying around).. Anyway, I've got some monetary
>>> amounts expressed as fixed point integers and also some percentages
>>> expressed the same way (e.g. 4% is 4s).. Anyway, I'd like to format
>>> these numbers as typical money amounts or percentages respectively..
>>> I was playing around with some of the built-in functions for integers
>>> to try to specify my own formatting but just don't know what needs to
>>> be specified to get my desired output..  I tried the following but it
>>> doesn't get the right set of digits in the output for things like $25.00
>>>
>>> moneyValue := '$', (fixedValue asFloat asString)
>>>
>>> Sample input/outputs:
>>> fixedValue = 25s.
>>> moneyValue = '$25.0'
>>>
>>> Any suggestions would be greatly appreciated!
>>>
>>> Thanks!
>>>
>>>
>>
>
>

Reply | Threaded
Open this post in threaded view
|

RE: Formatting monetary amounts and percentages

Boris Popov, DeepCove Labs (SNN)
One common way of storing monetary values using just minor units (i.e.
cents), so 12.45 would actually be stored as a 1245 integer,

Cheers,

-Boris

--
+1.604.689.0322
DeepCove Labs Ltd.
4th floor 595 Howe Street
Vancouver, Canada V6C 2T5
http://tinyurl.com/r7uw4

[hidden email]

CONFIDENTIALITY NOTICE

This email is intended only for the persons named in the message
header. Unless otherwise indicated, it contains information that is
private and confidential. If you have received it in error, please
notify the sender and delete the entire message including any
attachments.

Thank you.

-----Original Message-----
From: Dave Stevenson [mailto:[hidden email]]
Sent: Monday, February 05, 2007 12:01 PM
To: Rick Flower
Cc: Visualworks Mailing List
Subject: Re: Formatting monetary amounts and percentages

If I understand correctly, you want to avoid storing a float in the db
to represent aFixedPoint in the domain? I'm not the guy to ask about db
stuff, but I have a vague feeling that there is a proper way to do this.

Dave

Rick Flower wrote:
> Dave --
>
> Good questions.. I've got my data coming out of a database and it
> populates some of my ST objects with various items including some
> percentages, etc.. My percentages in the database are expressed as
"4.2"
> if the value is 4.2% instead of 0.42.. I need to revisit Postgres to
> make sure that's the best way to store that data (and certainly OT for

> this list).. All of my code is a work-in-progress and needs further
> refinement and I'm currently going through all of that code to make
sure
> things are behaving well.. I chose not to use floats for the obvious
> imprecise reasons that I'm sure you're aware of.. I just need to make
> sure that the translation between the database data and my ST objects
is
> correct and functioning..  Thanks for bringing up these items as I'll
be

> looking at them further..
>
> -- Rick
>
> Dave Stevenson wrote:
>> You've gotten lots of feedback on formatting and printing. However,
>> what does not make sense to me from your original post is why you
>> would represent a currency with precision zero? Instead of 25s, why
>> aren't you using 25.00s for all currencies?
>>
>> And 4s is 400%, not 4%, so I would use 0.04s for this one.
>>
>> Dave
>>
>> Rick Flower wrote:
>>> Hi all..
>>>
>>> It seems to me that I may have asked this before, but couldn't find
>>> my notes (and didn't seem to find anything in a few of my online PDF

>>> Smalltalk books I had lying around).. Anyway, I've got some monetary

>>> amounts expressed as fixed point integers and also some percentages
>>> expressed the same way (e.g. 4% is 4s).. Anyway, I'd like to format
>>> these numbers as typical money amounts or percentages respectively..
>>> I was playing around with some of the built-in functions for
integers
>>> to try to specify my own formatting but just don't know what needs
to
>>> be specified to get my desired output..  I tried the following but
it
>>> doesn't get the right set of digits in the output for things like
$25.00

>>>
>>> moneyValue := '$', (fixedValue asFloat asString)
>>>
>>> Sample input/outputs:
>>> fixedValue = 25s.
>>> moneyValue = '$25.0'
>>>
>>> Any suggestions would be greatly appreciated!
>>>
>>> Thanks!
>>>
>>>
>>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Formatting monetary amounts and percentages

Mike Hales
Postgres has a deprecated money data type as well as the NUMERIC data  
type which allows you to set the scale and precision when you create  
the column.  This should map perfectly to FixedPoint in VW.

Mike

On Feb 5, 2007, at 3:13 PM, Boris Popov wrote:

> One common way of storing monetary values using just minor units (i.e.
> cents), so 12.45 would actually be stored as a 1245 integer,
>
> Cheers,
>
> -Boris
>
> --
> +1.604.689.0322
> DeepCove Labs Ltd.
> 4th floor 595 Howe Street
> Vancouver, Canada V6C 2T5
> http://tinyurl.com/r7uw4
>
> [hidden email]
>
> CONFIDENTIALITY NOTICE
>
> This email is intended only for the persons named in the message
> header. Unless otherwise indicated, it contains information that is
> private and confidential. If you have received it in error, please
> notify the sender and delete the entire message including any
> attachments.
>
> Thank you.
>
> -----Original Message-----
> From: Dave Stevenson [mailto:[hidden email]]
> Sent: Monday, February 05, 2007 12:01 PM
> To: Rick Flower
> Cc: Visualworks Mailing List
> Subject: Re: Formatting monetary amounts and percentages
>
> If I understand correctly, you want to avoid storing a float in the db
> to represent aFixedPoint in the domain? I'm not the guy to ask  
> about db
> stuff, but I have a vague feeling that there is a proper way to do  
> this.
>
> Dave
>
> Rick Flower wrote:
>> Dave --
>>
>> Good questions.. I've got my data coming out of a database and it
>> populates some of my ST objects with various items including some
>> percentages, etc.. My percentages in the database are expressed as
> "4.2"
>> if the value is 4.2% instead of 0.42.. I need to revisit Postgres to
>> make sure that's the best way to store that data (and certainly OT  
>> for
>
>> this list).. All of my code is a work-in-progress and needs further
>> refinement and I'm currently going through all of that code to make
> sure
>> things are behaving well.. I chose not to use floats for the obvious
>> imprecise reasons that I'm sure you're aware of.. I just need to make
>> sure that the translation between the database data and my ST objects
> is
>> correct and functioning..  Thanks for bringing up these items as I'll
> be
>> looking at them further..
>>
>> -- Rick
>>
>> Dave Stevenson wrote:
>>> You've gotten lots of feedback on formatting and printing. However,
>>> what does not make sense to me from your original post is why you
>>> would represent a currency with precision zero? Instead of 25s, why
>>> aren't you using 25.00s for all currencies?
>>>
>>> And 4s is 400%, not 4%, so I would use 0.04s for this one.
>>>
>>> Dave
>>>
>>> Rick Flower wrote:
>>>> Hi all..
>>>>
>>>> It seems to me that I may have asked this before, but couldn't find
>>>> my notes (and didn't seem to find anything in a few of my online  
>>>> PDF
>
>>>> Smalltalk books I had lying around).. Anyway, I've got some  
>>>> monetary
>
>>>> amounts expressed as fixed point integers and also some percentages
>>>> expressed the same way (e.g. 4% is 4s).. Anyway, I'd like to format
>>>> these numbers as typical money amounts or percentages  
>>>> respectively..
>>>> I was playing around with some of the built-in functions for
> integers
>>>> to try to specify my own formatting but just don't know what needs
> to
>>>> be specified to get my desired output..  I tried the following but
> it
>>>> doesn't get the right set of digits in the output for things like
> $25.00
>>>>
>>>> moneyValue := '$', (fixedValue asFloat asString)
>>>>
>>>> Sample input/outputs:
>>>> fixedValue = 25s.
>>>> moneyValue = '$25.0'
>>>>
>>>> Any suggestions would be greatly appreciated!
>>>>
>>>> Thanks!
>>>>
>>>>
>>>
>>
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: Formatting monetary amounts and percentages

Rick Flower
Mike Hales wrote:
> Postgres has a deprecated money data type as well as the NUMERIC data
> type which allows you to set the scale and precision when you create the
> column.  This should map perfectly to FixedPoint in VW.

I just went and checked and my pgsql tables are using numeric types but
are not specifying scale/precision (e.g. they just show up as
"numeric"), so I should probably double-check my descriptors in Glorp
which is how I tagged them with "types"..

Thanks!