|
-
Apr 4th, 2001, 06:21 PM
#1
Thread Starter
Junior Member
Thanks for the reply Chris but i still can't get it to work.
This is what I am trying to do.
One text box has a decimal numer with unlimited decimal places.
the other has a whole number and when i tab out of the box with the whole number it multiplies one by the other and displays the result in a seperate text box. i want the result to be 2 decimal places long in the result text box as i am dealing with currency,
I would be grateful for any Help
thanks
Ciara
-
Apr 4th, 2001, 06:32 PM
#2
Fanatic Member
Try:
Code:
Formatcurrency(number,2)
-
Apr 4th, 2001, 06:35 PM
#3
There's also the Round function.
Code:
MyNum = Round(MyNum, 2)
-
Apr 4th, 2001, 06:36 PM
#4
Thread Starter
Junior Member
Thanks
Thanks - greatly appreciated!!
-
Apr 4th, 2001, 06:44 PM
#5
Thread Starter
Junior Member
where should i put that in?
Under Lost Focus for when i tab out of the box?
Claire
Sorry I have only just started learning VB.
thanks
claire
-
Apr 4th, 2001, 06:55 PM
#6
-
Apr 4th, 2001, 06:55 PM
#7
Fanatic Member
Megatron,
I have a problem with the round function:
Private Sub Command1_Click()
MsgBox Round(1.5)
MsgBox Round(2.5)
End Sub
Both return 2
-
Apr 4th, 2001, 07:04 PM
#8
Try
MsgBox Round(1.5, 2)
I'm sure if this'll work, because I do not have VB6 (but I've read about this function).
-
Apr 4th, 2001, 07:48 PM
#9
Hyperactive Member
Originally posted by JamesM
I have a problem with the round function:
Is this a seperate question to Claire's?
Megatron's code works for Claire's problem.
If you are confused as to why both of your rounds return 2, then this is correct. Rounding numbers always moves a .5 value to the nearest even number. This is called rounding off. Rounding down is when the number always goes to the number below. i.e. 3.5 becomes 3, and rounding up goes to the nearest number above. All of these events only happen when the decimal is exactly .5
I hope this clarifies things a bit,
SD
"I'd rather have a full bottle in front of me than a full frontal lobotomy!"
-
Apr 4th, 2001, 10:20 PM
#10
Fanatic Member
Meg and SD,
Let me clarify:
Code:
Private Sub Command1_Click()
MsgBox Round(10.115, 2)
MsgBox Round(10.125, 2)
'Both return 10.12 ?:eek:
End Sub
But
Code:
Private Sub Command2_Click()
MsgBox FormatCurrency(10.115, 2)
MsgBox FormatCurrency(10.125, 2)
'return the correct amounts of 10.12 And 10.13 respectively
End Sub
Statistically the round function works but this can create problems for currency calculations as in Claires case.
-
Apr 5th, 2001, 09:33 AM
#11
Hyperactive Member
Ah! Sorry James, I didn't seewhat you were getting at originally.
You are quite right, but then again so is Megatron.
The round function is used in large systems (such as payroll) to try to statistically remove all the half-pennies that would be left in the system (ala Superman III)., Whilst this isn't really a problem (the money isn't actually transfered until the payroll is ran), it is considered an equitable solution.
i.e. Rounding up favours the employees and rounding down favours the managers. I don't know if anyone ever really takes any of this stuff seriously, but I suppose some sad accountant somewhere probably does!!!
For Caires purposes she could use either and argue the case, but it's probably best to avoid the argument and use FormatCurrency IMHO.
Cheers,
SD
"I'd rather have a full bottle in front of me than a full frontal lobotomy!"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|