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:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* 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
Go Back   Tech Support Forum > Design Forum > Web Design & Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Web Design & Programming Discussion of web design, and server-side & client-side scripting

Reply
 
LinkBack Thread Tools
Old 04-06-2008, 05:17 PM   #1 (permalink)
Registered User
 
Spankdacamel4me's Avatar
 
Join Date: Mar 2007
Location: California
Posts: 36
OS: Windows XP Home

My System

Send a message via AIM to Spankdacamel4me
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.
Spankdacamel4me is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
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

Old 04-06-2008, 07:05 PM   #2 (permalink)
Registered User
 
Join Date: Apr 2008
Location: Oklahoma City
Posts: 26
OS: xp(sp2), OSX(10.5)


Re: Visual Studio 2008 Question

A few questions: what language are you using, also are start with a string of text or some other type.
snowman7000 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 04-07-2008, 07:55 PM   #3 (permalink)
Registered User
 
Spankdacamel4me's Avatar
 
Join Date: Mar 2007
Location: California
Posts: 36
OS: Windows XP Home

My System

Send a message via AIM to Spankdacamel4me
Re: Visual Studio 2008 Question

Quote:
Originally Posted by snowman7000 View Post
A few questions: what language are you using, also are start with a string of text or some other type.
I am programming in Visual Basic, and for your second question I dont really understand what you are asking sorry.
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.
Spankdacamel4me is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 04-08-2008, 12:08 AM   #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 "
snowman7000 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 04-08-2008, 01:44 AM   #5 (permalink)
Registered User
 
Spankdacamel4me's Avatar
 
Join Date: Mar 2007
Location: California
Posts: 36
OS: Windows XP Home

My System

Send a message via AIM to Spankdacamel4me
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.
Spankdacamel4me is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 04:17 PM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85