469,352 Members | 1,697 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

FormatCurrency and converting back to a number

I have a field that has been formatted using the vb.net FormatCurrency
method. Now, I need to get the amount back into a regular field so I
can use it for calculations. Is there an easy way to remove the
formatting characters ($,) ?

I suppose I could always use the replace function to remove the $ and
comma, but I wasn't sure if there was any easier way, i.e. Format(...)

TIA,
Mark
Nov 21 '05 #1
5 20901
Mark,

You mean something as this?

Dim a As Decimal = 10.1D
TextBox1.Text = FormatCurrency(a)
Dim b As Decimal = CDec(TextBox1.Text)

Cor

"Mark"
I have a field that has been formatted using the vb.net FormatCurrency
method. Now, I need to get the amount back into a regular field so I
can use it for calculations. Is there an easy way to remove the
formatting characters ($,) ?

I suppose I could always use the replace function to remove the $ and
comma, but I wasn't sure if there was any easier way, i.e. Format(...)

TIA,
Mark

Nov 21 '05 #2
Or even assiging to a decimal should work fine if you have Option Strict Off.

Parsing for a $ sign is always prone to probelms when your program runs on a
system that has a different currency symbol.

Rgds,
Anand
http://www.dotnetindia.com

"Mark" wrote:
I have a field that has been formatted using the vb.net FormatCurrency
method. Now, I need to get the amount back into a regular field so I
can use it for calculations. Is there an easy way to remove the
formatting characters ($,) ?

I suppose I could always use the replace function to remove the $ and
comma, but I wasn't sure if there was any easier way, i.e. Format(...)

TIA,
Mark

Nov 21 '05 #3
Yep. I was trying to use Convert.ToDouble and it was crashing... I
hadn't even thought of using the previous CDbl command....

Many thanks.....
"Cor Ligthert" <no**********@planet.nl> wrote in message news:<us**************@TK2MSFTNGP14.phx.gbl>...
Mark,

You mean something as this?

Dim a As Decimal = 10.1D
TextBox1.Text = FormatCurrency(a)
Dim b As Decimal = CDec(TextBox1.Text)

Cor

"Mark"
I have a field that has been formatted using the vb.net FormatCurrency
method. Now, I need to get the amount back into a regular field so I
can use it for calculations. Is there an easy way to remove the
formatting characters ($,) ?

I suppose I could always use the replace function to remove the $ and
comma, but I wasn't sure if there was any easier way, i.e. Format(...)

TIA,
Mark

Nov 21 '05 #4
On Mon, 6 Sep 2004 05:39:08 -0700, Anand[MVP] wrote:
Or even assiging to a decimal should work fine if you have Option Strict Off.

Parsing for a $ sign is always prone to probelms when your program runs on a
system that has a different currency symbol.

Rgds,
Anand
http://www.dotnetindia.com

"Mark" wrote:


Or just use Decimal.Parse or Double.Parse methods :)

Dim dec As Decimal = Decimal.Parse ("$1,250.25", NumberStyles.Currency)

or

Dim dbl As Double = Double.Parse ("$1,250.25", NumberStyles.Currency)

These methods are aware of currency symbol settings, so you don't have to
worry about the parsing issues involved. I would tend to use
Decimal.Parse, though since Decimal works better with monetary values :)
--
Tom Shelton [MVP]
Nov 21 '05 #5
Mark,

It is not previous, it is one of the methods advised to use because it has
much more power than the single Net methods because there is added
functionality (and because there is no Microsoft indexer involved which can
confuse me) I would not know why not to use them.

It is full dotNet.

Cor


Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Andrzej Jan Taramina | last post: by
1 post views Thread by Donald Firesmith | last post: by
2 posts views Thread by Alex Buell | last post: by
4 posts views Thread by =?Utf-8?B?Vmlua2k=?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.