# Help with formatting

[b][red]This message was edited by the Moderator at 2002-4-1 16:52:55[/red][/b][hr]
I'm having difficulty with the Format function. I have created some code to figure the averages of a set of inputs. When I type my code, I want the numbers to be in the format "0.00" but if the average ends up being a whole number (integer), the code will not force it to be followed by .00. In other words, if I want to get 480.00, I am only getting 480 with no decimal point or zeros. Here is my code, please help if you can. Thanks!

'create a loop to display the averages _
'of each score (verbal, quantitative, _
'and analytical) for all entered students

Dim a As Integer
For a = 1 To UBound(fStudents)
VAverage = (VAverage + fStudents(a).VScore / StudentIndex)
QAverage = (QAverage + fStudents(a).QScore / StudentIndex)
AAverage = (AAverage + fStudents(a).AScore / StudentIndex)
Next a

'display averages in the format "0.00"
'round averages up to the next 1/100th (.00)

VAverage = Format(Round(VAverage, 2), "0.00")
QAverage = Format(Round(QAverage, 2), "0.00")
AAverage = Format(Round(AAverage, 2), "0.00")

• : [b][red]This message was edited by the Moderator at 2002-4-1 16:52:55[/red][/b][hr]
: I'm having difficulty with the Format function. I have created some code to figure the averages of a set of inputs. When I type my code, I want the numbers to be in the format "0.00" but if the average ends up being a whole number (integer), the code will not force it to be followed by .00. In other words, if I want to get 480.00, I am only getting 480 with no decimal point or zeros. Here is my code, please help if you can. Thanks!
:
:
:
: 'create a loop to display the averages _
: 'of each score (verbal, quantitative, _
: 'and analytical) for all entered students
:
: Dim a As Integer
: For a = 1 To UBound(fStudents)
: VAverage = (VAverage + fStudents(a).VScore / StudentIndex)
: QAverage = (QAverage + fStudents(a).QScore / StudentIndex)
: AAverage = (AAverage + fStudents(a).AScore / StudentIndex)
: Next a
:
: 'display averages in the format "0.00"
: 'round averages up to the next 1/100th (.00)
:
: VAverage = Format(Round(VAverage, 2), "0.00")
: QAverage = Format(Round(QAverage, 2), "0.00")
: AAverage = Format(Round(AAverage, 2), "0.00")
:

Format(16.725, "0.00") = 16.73
Format(16.724, "0.00") = 16.72
Format(16.7, "0.00") = 16.70
Format(16, "0.00") = 16.00

Seems that it works fine for me. Of course, I don't have the Round function so maybe that is messing it up somehow? Format appears to do it's own rounding though. Maybe that's only when it's a number, I don't know...
• : : [b][red]This message was edited by the Moderator at 2002-4-1 16:52:55[/red][/b][hr]
: : I'm having difficulty with the Format function. I have created some code to figure the averages of a set of inputs. When I type my code, I want the numbers to be in the format "0.00" but if the average ends up being a whole number (integer), the code will not force it to be followed by .00. In other words, if I want to get 480.00, I am only getting 480 with no decimal point or zeros. Here is my code, please help if you can. Thanks!
: :
: :
: :
: : 'create a loop to display the averages _
: : 'of each score (verbal, quantitative, _
: : 'and analytical) for all entered students
: :
: : Dim a As Integer
: : For a = 1 To UBound(fStudents)
: : VAverage = (VAverage + fStudents(a).VScore / StudentIndex)
: : QAverage = (QAverage + fStudents(a).QScore / StudentIndex)
: : AAverage = (AAverage + fStudents(a).AScore / StudentIndex)
: : Next a
: :
: : 'display averages in the format "0.00"
: : 'round averages up to the next 1/100th (.00)
: :
: : VAverage = Format(Round(VAverage, 2), "0.00")
: : QAverage = Format(Round(QAverage, 2), "0.00")
: : AAverage = Format(Round(AAverage, 2), "0.00")
: :
:
: Format(16.725, "0.00") = 16.73
: Format(16.724, "0.00") = 16.72
: Format(16.7, "0.00") = 16.70
: Format(16, "0.00") = 16.00
:
: Seems that it works fine for me. Of course, I don't have the Round function so maybe that is messing it up somehow? Format appears to do it's own rounding though. Maybe that's only when it's a number, I don't know...
:

Try the FormatNumber function:

FormatNumber(16.725,2,vbtrue,vbfalse,vbfalse)