Validating decimal size

Posts   
 
    
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 21-Nov-2006 19:34:37   

Hello All,

Does anyone know of a way to test a decimal for the number of places it has before and after the decimal?

I need to do something like this.

decimal value1 = 172.45; // If value1 has more then two places before the decimal return zero. // Or if value1 has more then two places after the decimal return zero.

The reason that I need to do this is that I have a calculation being done and the result comes out to be something like value1. The value then is saved to a database column that is a decimal (4,2) which then causes an error at the database level. I would like to test to decimal value before this happens.

Thanks,

Aaron

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 22-Nov-2006 02:01:47   

I would test to see if the value is above a 99 to test before the decimal and I would round the number too 2 decimals to take care of more than two decimal places.