Currency
-
I am having problems trying to change a number into a dollar amount. For example, an object = $10.50, it will only allow me to have 10.5. I am not sure how or what to do to have it with the dollar sign and with 2 decimal places if it = $10.00. Thank you, ibok23
-
Fomat would be under properties right? I do not have that under my properties. I am using visual basic.net. Thank you, ibok23
You're a real beginner at this aren't you? What you would do is store the decimal version of the currency in a variable. THen when you need to show the value in a currency format, you supply the Format specification. Something like this:
Dim amount As Single
amount = 10.5
Console.WriteLine("Amount is " & Format(amount, "Currency"))
Console.WriteLine("Amount is " & Format(amount, "C"))
Console.WriteLine("Amount is " & Format(amount, "$###,##0.00"))All three Format specifications do the exact same thing. The one exception is the "Currency" and "C" specifications will use the format of the Windows Locale currentcy format, specified in the Regional and Language Options Control Panel. RageInTheMachine9532
-
You're a real beginner at this aren't you? What you would do is store the decimal version of the currency in a variable. THen when you need to show the value in a currency format, you supply the Format specification. Something like this:
Dim amount As Single
amount = 10.5
Console.WriteLine("Amount is " & Format(amount, "Currency"))
Console.WriteLine("Amount is " & Format(amount, "C"))
Console.WriteLine("Amount is " & Format(amount, "$###,##0.00"))All three Format specifications do the exact same thing. The one exception is the "Currency" and "C" specifications will use the format of the Windows Locale currentcy format, specified in the Regional and Language Options Control Panel. RageInTheMachine9532
-
Yes, I am a newbie. I have a box that is going to = $10.00. So I would write: dim baserate as double = 84.5 costofroom.text = Console.writeline(Format(amount,"Currency")) am i close Thank you, ibok23
Not quite... I'm assuming you have a TextBox on your Form called costofroom. I'm also assuming that you want the 'baserate' to be displayed in the TextBox and not 'amount' like in my example code.
dim baserate as double = 84.5
costofroom.text = Format(baserate,"Currency")RageInTheMachine9532
-
Not quite... I'm assuming you have a TextBox on your Form called costofroom. I'm also assuming that you want the 'baserate' to be displayed in the TextBox and not 'amount' like in my example code.
dim baserate as double = 84.5
costofroom.text = Format(baserate,"Currency")RageInTheMachine9532
sorry about that.. i tried. ok, I have put that in.. have not tried one more error. if I have $0.00 dollars as the amount for a box additonalguestcharge.text I put... additionalguesstcharge.text = format(0,"currency") getting an error..but of course. now what. By the way thanks for all the input. Thank you, ibok23
-
sorry about that.. i tried. ok, I have put that in.. have not tried one more error. if I have $0.00 dollars as the amount for a box additonalguestcharge.text I put... additionalguesstcharge.text = format(0,"currency") getting an error..but of course. now what. By the way thanks for all the input. Thank you, ibok23
Try this... Dim amount as double amount = 10.5 Console.Writeline(amount.ToString("C")) Free your mind...
-
sorry about that.. i tried. ok, I have put that in.. have not tried one more error. if I have $0.00 dollars as the amount for a box additonalguestcharge.text I put... additionalguesstcharge.text = format(0,"currency") getting an error..but of course. now what. By the way thanks for all the input. Thank you, ibok23
maybe try
Console.Writeline(Format(0,"$#,###0.00"))
i havent tried this but i remember i used something just like it before, i forget exactly what it was. mess around with that if it gives an error. itll b just around the corner. ------------------------ Jordan. III
-
sorry about that.. i tried. ok, I have put that in.. have not tried one more error. if I have $0.00 dollars as the amount for a box additonalguestcharge.text I put... additionalguesstcharge.text = format(0,"currency") getting an error..but of course. now what. By the way thanks for all the input. Thank you, ibok23
First, what's the error? RageInTheMachine9532
-
First, what's the error? RageInTheMachine9532
-
First, what's the error? RageInTheMachine9532
I finally got it done. Now i am haveing problems with my total. I am trying to add three boxes together. I love math and I know what to do. I put total.text = ((subtotal.text) + (additionalguestcharge.text) + (rollbed.text)) in my answer it gives me $209.00$5.00$10.00 instead of adding it up. This is weird. Thank you, ibok23
-
I finally got it done. Now i am haveing problems with my total. I am trying to add three boxes together. I love math and I know what to do. I put total.text = ((subtotal.text) + (additionalguestcharge.text) + (rollbed.text)) in my answer it gives me $209.00$5.00$10.00 instead of adding it up. This is weird. Thank you, ibok23
-
I finally got it done. Now i am haveing problems with my total. I am trying to add three boxes together. I love math and I know what to do. I put total.text = ((subtotal.text) + (additionalguestcharge.text) + (rollbed.text)) in my answer it gives me $209.00$5.00$10.00 instead of adding it up. This is weird. Thank you, ibok23
ibok23 wrote: total.text = ((subtotal.text) + (additionalguestcharge.text) + (rollbed.text)) That's because you adding String of characters together, not number values. What's going to make you redesign your code is the fact the the numbers you see in the TextBoxs can't be used in calculations. TextBoxs are lousy places to keep number values. You should only use them to display results. Since I can't see all of your code, I can't tell you exactly what you have to do to make things right, but I can tell you you need to keep the value you use in calculations in numeric type variables. You also need to rename your TextBoxes so that their names don't conflict with any other variable names. I would suggest renaming them with a 'txt' prefex, like this:
total becomes txtTotal subtotal becomes txtSubTotal additionalguestcharge becomes txtAdditionalGuestCharge ...
Now, keep your numeric values in variables something like this:
Dim subtotal As Double Dim additionalguestcharge as Double Dim rollbed as Double Dim total as Double total = subtotal + additionalguestcharge + rollbed txtTotal.Text = Format(total, "C")
Get the idea? RageInTheMachine9532
-
I finally got it done. Now i am haveing problems with my total. I am trying to add three boxes together. I love math and I know what to do. I put total.text = ((subtotal.text) + (additionalguestcharge.text) + (rollbed.text)) in my answer it gives me $209.00$5.00$10.00 instead of adding it up. This is weird. Thank you, ibok23
when adding text in labels, textboxes, etc etc, you must convert them to a number first. they are concatenating (putting together) the text, with what you are doing right now. do something like:
total.text = CInt(CInt(subtotal.text) + CInt(additionalguestcharge.text) + CInt(rollbed.text))
------------------------ Jordan. III -
ibok23 wrote: total.text = ((subtotal.text) + (additionalguestcharge.text) + (rollbed.text)) That's because you adding String of characters together, not number values. What's going to make you redesign your code is the fact the the numbers you see in the TextBoxs can't be used in calculations. TextBoxs are lousy places to keep number values. You should only use them to display results. Since I can't see all of your code, I can't tell you exactly what you have to do to make things right, but I can tell you you need to keep the value you use in calculations in numeric type variables. You also need to rename your TextBoxes so that their names don't conflict with any other variable names. I would suggest renaming them with a 'txt' prefex, like this:
total becomes txtTotal subtotal becomes txtSubTotal additionalguestcharge becomes txtAdditionalGuestCharge ...
Now, keep your numeric values in variables something like this:
Dim subtotal As Double Dim additionalguestcharge as Double Dim rollbed as Double Dim total as Double total = subtotal + additionalguestcharge + rollbed txtTotal.Text = Format(total, "C")
Get the idea? RageInTheMachine9532
Thanks - I see what I was doing wrong, I don't understand it all the way, but I do see. Now one more question if you don't mind How do you get to set a date picker back to the current date when you push the clear button? I want them to be able when they push the clear button to default back to the current date.
-
Thanks - I see what I was doing wrong, I don't understand it all the way, but I do see. Now one more question if you don't mind How do you get to set a date picker back to the current date when you push the clear button? I want them to be able when they push the clear button to default back to the current date.
Anonymous wrote: I want them to be able when they push the clear button to default back to the current date. Easy enough ... just set the Value property of the DateTimePicker control to the current Date using Now(). Put this code in the handler for the Clear button click:
dtpArrival.Value = Now() dtpCheckout.Value = Now()
RageInTheMachine9532