![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Web Design & Programming Discussion of web design, and server-side & client-side scripting |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
|
Visual Studio 2008 Question
I'm trying to figure out a way to split currency. Heres an example..
Instead of $27.58 as my result I would rather see 27 Dollars 58 Cents I'm just not sure how I can receive the cents by itself. Thank you :) - Camel
__________________
If at first you don't succeed, Find out if the loser gets anything. The early bird gets the worm, but The early worm is for the birds. |
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#3 (permalink) | |
|
Registered User
|
Re: Visual Studio 2008 Question
Quote:
To break it down a bit more here is another example. I havent really even begun on the code yet because I didnt know where to start, but here is a bit of pseudo-code to get an idea... lblFinalCost.Text = FormatNumber(Val(txtCost1.Text) * Val(txtCost2.Text)), 2) cost1 = $10 cost2 = $10.12 FinalCost = $20.12 I'm trying to find out how I can split $20.12 into "20 Dollars 12 Cents" in the label. I need the cents saved to a separate variable or something. I can't figure how I would separate the cents from the dollars so I can display the total as "20 Dollars 12 Cents". I hope that made a bit more sense this time. Extremely dumbed down example, but its kind of hard to explain what I am looking for. Any input is appreciated, thank you. - Camel
__________________
If at first you don't succeed, Find out if the loser gets anything. The early bird gets the worm, but The early worm is for the birds. |
|
|
|
|
|
|
#4 (permalink) |
|
Registered User
Join Date: Apr 2008
Location: Oklahoma City
Posts: 26
OS: xp(sp2), OSX(10.5)
|
Re: Visual Studio 2008 Question
I am more of a C# guy since I have done more work in C++, Javascript, Java and C# so I will give you this code that I know works in C# and hopefully compilable translation to a VB (I only have the express versions of C#, C++ and Web Developer as I don't like to use VB and only use it at work when I am maintaining legacy code and what I do at home is only small personal projects so I don't need the full edition.)
'// string txtDollarsAndCents = txtCost.Text string txtDollarsAndCents = "$27.58"; txtDollarsAndCents.Trim(); double DollarsAndCents = Double.Parse( txtDollarsAndCents, System.Globalization.NumberStyles.AllowCurrencySymbol | System.Globalization.NumberStyles.AllowDecimalPoint | System.Globalization.NumberStyles.AllowThousands ); int Dollars = Convert.ToInt32( Math.Floor( DollarsAndCents ) ); int Cents = Convert.ToInt32( (DollarsAndCents % 1.0) * 100 ); target.Text = Dollars + " Dollars " + Cents + " Cents "; ' I think this should work, I am sorry that I cannot insure this will compile. Dim DollarsAndCents As Double Dim Dollars As Integer Dim Cents As Integer Dim txtDollarsAndCents As String = "$27.58" ' could assign value but for example hard code one above 'txtDollarsAndCents = txtCost.Text ' This will take off any extra whitespace on the ends if it is user input txtDollarsAndCents.Trim() ' this will covert the string type to a numeric type that can have a fraction DollarsAndCents = Double.Parse( txtDollarsAndCents, System.Globalization.NumberStyles.AllowCurrencySymbol Or System.Globalization.NumberStyles.AllowDecimalPoint Or System.Globalization.NumberStyles.AllowThousands ) ' gets the whole number portion (dollars) and assigns it to a numeric type, since will only be whole number choose numeric type that not contain fractional part Dollars = Convert.ToInt32( Math.Floor( DollarsAndCents ) ' gets the fractional part (cents) and assigns it to a numeric type, since will only be whole number choose numeric type that not contain fractional part Cents = Convert.ToInt32( (DollarsAndCents Mod 1.0) * 100 ) target.Text = Dollars & " Dollars " & Cents & " Cents " |
|
|
|
|
|
#5 (permalink) |
|
Registered User
|
Re: Visual Studio 2008 Question
Thanks very much for the code. I started the code at my house and am now currently on a different computer so i won't have the chance to compile it and test it out tonight, but can't wait to give it a go first thing tomorrow. Seems to make more sense looking at it now. Thanks very much for your help.
- Camel
__________________
If at first you don't succeed, Find out if the loser gets anything. The early bird gets the worm, but The early worm is for the birds. |
|
|
|
![]() |
| Thread Tools | |
|
|