Click to See Complete Forum and Search --> : problem with CInt function
stevem2004
10-07-2004, 06:59 AM
Hi,
I am using the CInt function for my database entries, this is not a problem, but this rounds all values to the nearest whole number, so if I have 126.75 in the database, then this is rounded to 127.
Is there any way to stop it rounding the numbers?
Thanks
Steve
David Harrison
10-07-2004, 07:16 AM
Well Int stands for Integer, so no. CInt will round a number to the nearest integer, that's it's job if you like.
buntine
10-07-2004, 07:38 AM
VB uses the Single datatype for floats. The Cast Single (CSng) function will be helpful.
CSng(expression) '| <-- Format.
Dim a
a = "22.3332"
CSng(a) '| <-- Example. (Should return 22.3332 or 22.33)
Also, VBScript has a rounding function.
Round(expression, numOfPlaces) '| <-- Format.
Round(2.1234, 2) '| <-- example. (will return 2.12)
That may be useful.
Regards.
David Harrison
10-07-2004, 07:59 AM
What's the difference between CInt and Round?
stevem2004
10-07-2004, 08:31 AM
Many Thanks Buntine, the CSng function works perfectly.
buntine
10-07-2004, 09:59 AM
What's the difference between CInt and Round?
CInt will cast the expression to a whole Integer, thus removing any decimal places. Round gives you the option of keeping a certain number of decimal places. Round(2.333, 2) will return 2.33.
Regards.
David Harrison
10-07-2004, 02:58 PM
Ah thank-you, that could prove useful.
russell
10-08-2004, 02:06 AM
There is also a cdbl() function for floating point values...