truncating numbers

1. Senior Member
Join Date
Dec 1969
Posts
482

## truncating numbers

How can i truncate a number i.e. 3/5=0.6 but i want it to be 0 only without the decimal points.I have tried to use formatnumber method but it rounded the number.Please help..

2. Senior Member
Join Date
Dec 1969
Posts
2,334

## say that again

the question is not clear to me? Can you repeat that as what do you want?<BR>May be give a couple of examples.

3. Senior Member
Join Date
Dec 1969
Posts
19,082

## convert it into a string....

... then find the point with Instr, and use Left with this to crop it. easy.

4. Senior Member
Join Date
Dec 1969
Posts
482

## RE: say that again

Say i want to divide 9/5 then the answer would be 1.8 instead of having that as an answer i just want 1 as the answer which mean i just ignore the decimal part without rounding the number.

5. Senior Member
Join Date
Dec 1969
Posts
2,334

## you can use the soln by Atrax

6. Senior Member
Join Date
Dec 1969
Posts
482

## RE: convert it into a string....

can u give me example on how to do it..

7. Senior Member
Join Date
Dec 1969
Posts
19,082

## RE: convert it into a string....

shortNum = Left(CStr(longNum), Instr(CStr(longNum), "."))<BR><BR>

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

## YUCK and double YUCK!

All he needs is the INT function!<BR><BR>&#060;%<BR>divident = 6<BR>divisor = 10<BR>TruncatedResult = INT( dividend/divisor ) &#039; will be zero!<BR>%&#062;<BR><BR>INT is a function that tosses away any fractional part of a number WITHOUT ROUNDING.<BR><BR>There is also the FIX function, which works the same as INT for positive numbers, but the two have different behavior with negative numbers. Look them up.<BR><BR>Click on "VBScript Reference" in the left panel of this page.<BR><BR>Click on "Functions" in the list of topics that appears.<BR><BR>Click on the function name you are interested in.<BR><BR><BR><BR>

9. Senior Member
Join Date
Dec 1969
Posts
19,082

## RE: YUCK and double YUCK!

yeah, I know.

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

## Besides, that WILL NOT work!

shortNum = Left(CStr(longNum), Instr(CStr(longNum), "."))<BR>that will *INCLUDE* the decimal point in the answer!<BR><BR>ALSO...<BR><BR>You have to understand that VBScript *WILL* round numbers in order to display them in a reasonable number of digits!<BR><BR>So, for example, if the internal form of a number is<BR> longnum = 7.999999935<BR>and you do<BR> CSTR(longnum)<BR>you will get<BR> 8<BR>(not 8.0) as a result!<BR><BR>But, of course the *right* answer, the integer-only portion of that number is 7, not 8! Which, not so incidentally, INT(longnum) will give you.<BR><BR>

#### Posting Permissions

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