11 replies
by dklippert
by mruiz
by true_texan
I'm not sure how the formatting in Access 95 works, but there's always the mathematical aproach. Multiply the number by 10; take the integer of the number; and divide by 10. If n is your number, the formula would look something like:
n = INT(n*10)/10
The number may still display in currency (ie. $0.00), but the number would be rounded to the nearest 10th.
Hope this helps!
by mruiz
by c1980
A label would of course show what you want. But a text box, once it gets focus, shows the true value of the field. In order to display this as you want when the text boy gets the focus you need to set the data input/mask format of the text box to:"#,0.00", or whatever you want.
by mruiz
by bob sellman
The mathematical approach is the correct approach, but you've got to use the correct formula so that you round and you get to the right number of decimal places:
value = .01 * INT(.5 + (100 * value))
The .5 can be .49 or whatever suits your needs best for rounding. .5 will round up anything where the third decimal place in value is .5 or higher.
To get this to work, you should include the above code (substituting the name of the control, let's say txtValue, for value), as part of theonUpdate property of the control txtValue. So it would read:
me.txtValue = .01 * INT(.5 + (100 * me.txtValue))
Hope this helps.
by mruiz
by sl-campbell
A text box, when it gets the focus, will always show the true value assigned to it. This is normal, and it should be this way...
However, if you want it to show a different value, which is the apparently the case here, then you need to set the value of the text box in code. If you go to the code window, and select the Form_Current event and here do your calculations with a variable and THEN assign the results to the text box, formating it at the same time, you will get want you want because the text box is now being assigned to a variable that holds the rounded value instead of being assigned to a un-rounded value and THEN being rounded or formated.
Private Sub Form_Current()
Dim dCalc As Double
'doing some calculation each time the recordset is repositioned
dCalc = 123456789.234569
'Round and format the calculated value to 2 decimal places
Text1.Value = Format$(dCalc, "#,0.00")
End Sub
If the text box should hold the correct value, unformated, but the user should see the rounded value when the text box gets the focus, then you need to use the Input Mask of the text box as decsribed in answer #3.
by mruiz
by mruiz
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending