How to stop rounding numbers down/ up

Nats

Registered User.
Local time
Today, 15:37
Joined
Jun 21, 2007
Messages
26
Hi Guys,

In my form I have a couple of text boxes that you enter numbers to, one is set at '£' with 2 decimal places and the other at 'general' with 1 decimal place.

The trouble is in the '£' box if I type £9.33 it automatically changes it to £9.00 and then in the other text box if I put in 85.5 it automatically changes it to 86.

Can anyone advise me how I make it so I can put in just the £9.33 or 86 and it stay like that without it rounding it down/ up.

Thank you in advance.
 
Check the field's data type. If you are using Number, you need to check what kind of number you are using:

If it's a long integer (default), this is why you're seeing it being rounded off. Change it to any of those: single, double and decimal.

Single takes the least amount of space, but is smallest number (can't remember off the top of my head), while Double takes double the amount but can hold a much bigger number. Decimal is a hog, and never really used it.
 
As it looks like a money field you could always use Currency.
 
Check the field's data type. If you are using Number, you need to check what kind of number you are using:

If it's a long integer (default), this is why you're seeing it being rounded off. Change it to any of those: single, double and decimal.

Single takes the least amount of space, but is smallest number (can't remember off the top of my head), while Double takes double the amount but can hold a much bigger number. Decimal is a hog, and never really used it.

thnx man you just saved me :D
 
Single takes the least amount of space, but is smallest number (can't remember off the top of my head), while Double takes double the amount but can hold a much bigger number. Decimal is a hog, and never really used it.

Single uses four bytes and can store numbers up to a magnitude of about 10^38

Double is eight bytes and holds numbers up to a magnitude of about 10^308.

However both Double and Single have problems with arithmetic calculations because certain decimal numbers cannot be represented precisely in binary. For example the expression Int(63/0.7) returns 8 when the numbers are held as Single or Double.

Decimal is twelve bytes. It is a scaled integer so does not suffer the issue with decimal imprecision. It can store 28 digits which it holds as an integer along with a scale factor. By adjusting the Scale and Precision it can store numbers up to almost one with 28 decimal places through to about 10^28 with no decimal places. (However in a table it will only be displayed with a maximum of 14 decimal places.)

Int(63/CDec(0.7)) gets the right answer because the 0.7 is converted to an integer 7, with a scale factor of one decimal place before the arithmatic is evaluated.

Currency uses eight bytes and will hold numbers to the magnitude of about 10^15. It is also a Scaled Integer but fixed to a precision of four decimal places.
 
I use Currency for all numeric fields that will be used in arithmetic operations when they can't be defined as Integers. You can control the format so the field shows a % sign or nothing at all. It doesn't have to display dollars and cents so don't be confused by the name of the data type. Currency is limited to four decimal places but for most general business applications, that is sufficient. If I had a table of millions of rows, I would probably reconsider and use a more efficient data type when possible but I would also have to be prepared for floating point errors.
Luke Chung wrote a good article on the topic some years ago. You can find it at www.FMSINC.com along with lots of other good articles.
 

Users who are viewing this thread

Back
Top Bottom