Default decimal places
Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=14341
Printed Date: 30 March 2026 at 10:06am Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com
Topic: Default decimal places
Posted By: ub3rl337ch3ch
Subject: Default decimal places
Date Posted: 20 March 2005 at 7:17pm
|
Is there any way to get asp to stop rounding automatically? I know i can do a formatnumber(1.22, 2) so that it has the correct number of decimal places, but I don't want to have to write a format number for every single number in my code. Aside from anything else, I don't want my 2's to display as 2.00 just so 1.22 displays as 1.22 instead of 1. Its also a bit of a pain in the neck when i'm trying to work with a db that has decimal values galore.
|
Replies:
Posted By: ljamal
Date Posted: 21 March 2005 at 12:42am
ASP doesn't round automatically. If sounds like you you have a number conversion porblem with doubles changes to integer values.
------------- L. Jamal Walton
http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming
|
Posted By: Demon
Date Posted: 21 March 2005 at 1:55am
Try making a custom sub like this:
Sub rInt(iNumber,iDecs)
'Check if the number is a Whole Number or a Decimal
If FormatNumber(iNumber,iDecs) >
FormatNumber(iNumber,0) AND FormatNumber(iNumber,iDecs) <
(FormatNumber(iNumber,0)+1) Then
rInt = FormatNumber(iNumber,iDecs)
Else
rInt = Fix(iNumber)
End If
End Sub
|
Then all you have to do is call it by using it like: rInt(1.22,2)
There for rInt(2.00000,2) and rInt(2.000011,2) would give out 2
But rInt(2.0109,2) would give out 2.01 because 2 decimal places back is
a nonZero number. Respectively, rInt(2.000312,4) would give 2.0003.
------------- So Sayith the Demon.
|
|