Printing dollar amounts on forms

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

Printing dollar amounts on forms

Bruce A. Peaslee
If my user enters 123.4 in a text box, I want it to show $123.40 the
next time the dialog is opened. I've tried searching for how, but I
can't find the answer.

Peaslee


Reply | Threaded
Open this post in threaded view
|

Re: Printing dollar amounts on forms

Christopher J. Demers
Bruce A. Peaslee <[hidden email]> wrote in message
news:[hidden email]...
> If my user enters 123.4 in a text box, I want it to show $123.40 the
> next time the dialog is opened. I've tried searching for how, but I
> can't find the answer.

There are a few ways this could be done.  One way would be to use a
TypeConverter.  See NumberToText for an example.  Possibly you could create
your own converter to display a number the way you want.  You could also
consider creating your own Currency class and use a corresponding converter
to go back and forth.  Depending upon what you want to do with the number
there may be advantages to using your own Currency class.  One thing to note
is that in order for a TypeConverter subclass to be available as a choice in
the view composer text box typeConverter aspect the class needs to be in the
"MVP-Type Converters*" classification.  If you make this change while a view
composer is open you may need to close it and reopen it to see the new
option.

Hope that helps,

Chris


Reply | Threaded
Open this post in threaded view
|

Re: Printing dollar amounts on forms

Ian Bartholomew-5
Chris/Bruce,

A CurrencyToText TypeConverter is the sort of small addition to the Dolphin
image that I had in mind when I added the "Tweaks" page to my web site.
I've therefore implemented it and uploaded it to the site as a stand alone
class - intended for Dolphin 4.01 but I think I will probably work with
earlier versions.

For the Number to Text conversion you can specify the number of characters
to the left and right of the decimal place and ask for the left side to be
padded with either zero or space.

A Text to Number conversion has no formatting rules and answers an Float or
Integer as appropriate.

Thanks for the idea (I hope you don't mind me borrowing it) and if anyone
else has suggestions for small additions like this I would be interested in
hearing about them - no promises though <g>

Ian

http://www.iandb.org.uk


Reply | Threaded
Open this post in threaded view
|

Re: Printing dollar amounts on forms

Bruce A. Peaslee-2
Works like a charm. Decimal currency on the form, a float when I
inspect. Thanks!

It even does the conversion when you tab and the box loses the focus.
That's better than having it change only when you close and reopen the
form. Nice piece of work.

Also, since Smalltalk is open source, anyone can look and see how it's
done and modify it, say, to add commas at the appropriate places.

Peaslee

"Ian Bartholomew" <[hidden email]> wrote in message news:<RDcA7.521$h4.38065@stones>...

> Chris/Bruce,
>
> A CurrencyToText TypeConverter is the sort of small addition to the Dolphin
> image that I had in mind when I added the "Tweaks" page to my web site.
> I've therefore implemented it and uploaded it to the site as a stand alone
> class - intended for Dolphin 4.01 but I think I will probably work with
> earlier versions.
>
> For the Number to Text conversion you can specify the number of characters
> to the left and right of the decimal place and ask for the left side to be
> padded with either zero or space.
>
> A Text to Number conversion has no formatting rules and answers an Float or
> Integer as appropriate.
>
> Thanks for the idea (I hope you don't mind me borrowing it) and if anyone
> else has suggestions for small additions like this I would be interested in
> hearing about them - no promises though <g>
>
> Ian
>
> http://www.iandb.org.uk


Reply | Threaded
Open this post in threaded view
|

Re: Printing dollar amounts on forms

Ian Bartholomew-5
Bruce,

> It even does the conversion when you tab and the box loses the focus.
> That's better than having it change only when you close and reopen the
> form. Nice piece of work.

That's down to the underlying dialog behaviour so OA should be the ones
getting the pat on the back for that.

> Also, since Smalltalk is open source, anyone can look and see how it's
> done and modify it, say, to add commas at the appropriate places.

I was already going to add a bit to it - truncate to integer only (for cases
when you don't want the dp and fractional part) and also a selectable
currency symbol. I'll add support for commas as well.

Ian


Reply | Threaded
Open this post in threaded view
|

Re: Printing dollar amounts on forms

Ian Oldham-4
"Ian Bartholomew" <[hidden email]> wrote in message news:<spbB7.1275$h4.83138@stones>...

> Bruce,
>
> > It even does the conversion when you tab and the box loses the focus.
> > That's better than having it change only when you close and reopen the
> > form. Nice piece of work.
>
> That's down to the underlying dialog behaviour so OA should be the ones
> getting the pat on the back for that.
>
> > Also, since Smalltalk is open source, anyone can look and see how it's
> > done and modify it, say, to add commas at the appropriate places.
>
> I was already going to add a bit to it - truncate to integer only (for cases
> when you don't want the dp and fractional part) and also a selectable
> currency symbol. I'll add support for commas as well.
>
> Ian

Is this providing something different to Steve Waring's(?) Currency package?


    another Ian.


Reply | Threaded
Open this post in threaded view
|

Re: Printing dollar amounts on forms

Ian Bartholomew-5
Ian,

> Is this providing something different to Steve Waring's(?) Currency
> package?

I just had a look through the n/g archive and it was Steve Zara who came up
with a Currency package (which I wasn't aware of!!).

I've just downloaded his package [1] and they do similar jobs but is a
slightly different way, mainly that Steve defines a Currency class based on
ScaledDecimal whereas mine works with normal <number> objects.  I think mine
has a few more formatting options (leading zeros, currency symbol) but
there's not a lot of difference overall.

Thanks for pointing it out - it's good to have different packages available.

Ian

[1] Link on Steve's page at -
http://www.serf.org/steve/Dolphin/