Well, I don't know any better methods for truncating, but there are some good news: 1 if tooLongDecimal is zero, you don't get any exception as you are not dividing by zero, ever. The picture format works, but it's not quite flexible. You can't post replies to polls. I like Method 1 for truncating decimal values and plan to use it. Round assisting with a specific overload. If that digit is 0, you just drop it.
This is only representation of characters. This is exactly what this blog post talks about. I didn't notice that the decimal takes 2 decimal places which means 0. If it is zero, you do nothing. Just change the space holding periods to actual spaces.
. The only possible ways that I can think of doing it are either: 1. One would have to define multiple picture formats for each number of decimal places to keep. Sales tax calculations can result in 3 or more decimal places which are usually carried through to the final result, before rounding to 2 decimal places. The result can be converted back into numeric if necessary. However, sometimes it is necessary to truncate displayed numeric values to a specified number of decimal places without rounding. Therefore, we must change the six to a seven.
Put this in the format for the field. You can't edit your own events. I'm waiting to see what wwales comes up with. Whenever you use a variable, Access will convert the variable to the requisite type before passing it through to the equation. Now when I export the report to excel the display is 9.
If it is 1-4 then you also drop it. And that makes data easier to work with. Substring 0, 3 ' Write the results to the screen. Simply use the following code. Results, by default are truncated. In your example you used 9.
You broadened it and suggested a robust and comprehensive solution. There is an edge case here that you can overflow decimal by multiplying first, an edge case, but something I have come across. The big sign may say 3. Anything you do from there is already wrong. But sometimes you just want a shorter number. There is a problem with the above rule: i … t introduces an upward rounding bias.
To round to a particular place, look at the digit immediately to the right of the one you want to round to, in this case, the third decimal place. Just do not forget to include your math header cmath for most, math. TruncateEx 0 ; } Your algorithm results in some incorrect results. I am getting correct results with this. You Value Community's efforts and Community values your faith.
In excel for calculations purpose I need the exact data what I get from the database. Truncate d ' Result: 164 See also. I am not saying it's legal, but this example is just an illustration of the power of ordinary truncation. A slight alteration of my previous post also allows one to decide how many decimal positions to consider. If tha … t digit is 5, 6, 7, 8 or 9, increase your target digit by one and zero everything to the right of it out. Leonid, Another great technical article! Four or below, you round down.