Reputation: 21
I have the following code written by VBA in MS Access 2010. This code prints in the Label1.caption the number of this equation.
the_average = CDbl(TextBox1.Text) * 2 / 3 + CDbl(TextBox2.Text) / 3
the_average = Format(the_average, "#.###")
Label1.caption= the_average
Some of the operations have more than three decimal places. This code rounds the numbers when printing them in the caption of the label. For example if I have 1.66666666, it shows 1.667 and I want it to show 1.666 without rounding. How can I do that? Thanks in advance
Upvotes: 2
Views: 774
Reputation: 175768
You can take advantage of Int()
's truncation;
the_average = formatnumber(int(the_average * 1000) / 1000, 3)
You can omit formatnumber
if you don't want trailing zeros (.99 -> .990)
Upvotes: 0
Reputation: 7019
the_average = CDbl(TextBox1.Text) * 2 / 3 + CDbl(TextBox2.Text) / 3
the_average = Format(the_average, "#.####")
Label1.caption= Left(the_average,5)
If your final string can vary in length, you will have to use the InStr()
function (I believe that's it).
Upvotes: 1