![]() This isn't really necessary, because all versions of Basic, includingīasic and Visual Basic for Applications (VBA) handle mixed number formats Prints a value of "1.55" despite the fact that EVERYTHING (variables and Subject: RE: RE: How to truncate a number field to 2 decimal TestTruncate = CDbl(Left$(CStr(pdblVal), InStr(1, CStr(pdblVal), ".") +įrom: Michael Meyers-Jouan via vb-access-l Public Function TestTruncate(pdblVal As Double, pDecPos As Integer) As Why overly complicate things with variables and if statements that aren'tĪ slight alteration of my previous post also allows one to decide how many > truncate it and restore it back to a value. > You can convert to a string, find the decimal and take the string and The OP in asking the question might be better off with aįrom: gkoster via vb-access-l [mailto: Wednesday, Ap1:46 PM Sometimes the shortest bit of code is not Subject: RE: How to truncate a number field to 2 decimal I assume the OP wanted 1.55įrom: wwales via vb-access-l [mailto: Wednesday, Ap8:29 AM ![]() Note this is a rounded result not truncated. Truncate it and restore it back to a value.įrom: john via vb-access-l [mailto: Wednesday, Ap10:47 AM You can convert to a string, find the decimal and take the string and Need to do math on the value convert it back to the proper number typeįrom: b.calkins via vb-access-l [mailto: Wednesday, Ap12:57 PM (Just change the space holding periods to actual spaces.)Īgree, the best way to truncate and ensure you don't get tangled up in aįunction that wants to round is to manipulate a string and if you then TestTruncate2 = CDbl(Left$(CStr(pdblVal), InStr(1, CStr(pdblVal), ".") + 2)) Public Function TestTruncate2(pdblVal As Double) As Double ![]() However, the alternate solution offered (with a slight modification) will work. Thus in response to the original post, your solution does not work. hence the results would be what you are expecting. In the second situation, you passed a constant - which is not converted before the calculations. Anything you do from there is already wrong. Hence, in the first situation, Access converted "val" to an integer value (rounded) before inserting it into the equation because it assumed you wanted an integer result (because of the call to the "Int" conversion function. Whenever you use a variable, Access will convert the variable to the requisite type before passing it through to the equation. On the surface they look the same, but they are not. wait - there is a difference between your two postings.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |