need to stop rounding

# Thread: need to stop rounding

1. Junior Member
Join Date
Dec 1969
Posts
9

## need to stop rounding

The following I am using :<BR>&#060;%= formatNumber((intTotal*1.12), 2) %&#062;<BR> it is displaying only 2 decimals but here is what is going on <BR>let say total sales were 5.40 <BR>I am then looking for a total answer of 6.04..... <BR>I times by 1.12 to get this answer but I get 6.05......................due to the fact that 5.40 * 1.12= 6.048 I need it not <BR>to round the 8 and its rounding the 8 <BR>I am using a database field set to currency and 2 decimals <BR><BR><BR>

2. MGH
Senior Member
Join Date
Dec 1969
Posts
175

## RE: need to stop rounding

I wont say this is the best solution but you could do this<BR><BR>&#060;%= formatNumber((intTotal*1.12), 3) %&#062; <BR><BR>Notice that you are getting three decimal places. Convert the output to string using CStr function and then remove the last character from the string (Using Mid function)

3. Junior Member
Join Date
Dec 1969
Posts
9

## RE: need to stop rounding

Thanks MGH

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## That will *NEVER* work!

Suppose the actual answer is<BR> num = 5.999718<BR>FormatNumber( num, 3 ) will round that to<BR> 6.000<BR>And you chop off the last digit and you *still* get the wrong answer of<BR> 6.00<BR><BR>*************<BR><BR>If you want to *TRUNCATE* then you have to use the INT function in VBScript. Thus:<BR><BR>&#060;%= FormatNumber( INT(intTotal*1.12*100)/100, 2 ) %&#062;<BR><BR>See that? In pieces:<BR> temp = intTotal*1.12 &#039; let&#039;s say that indeed gives 5.999718<BR> temp2 = temp * 100 &#039; so now we have 599.9718<BR> temp3 = INT(temp2) &#039; which gets 599.0<BR> temp4 = temp3/100 &#039; which gets 5.99<BR> FormatNumber( 5.99, 2 ) &#039; gives you, indeed, 5.99<BR><BR>

5. MGH
Senior Member
Join Date
Dec 1969
Posts
175

## great. I hope greg makes the correction <eop&

.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•