→ Having trouble accessing our new support portal or creating a ticket? Please notify our team here

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Juha_Otava
Engaged Sweeper III
Why this works:

Convert(Decimal(2,1),tblDiskdrives.Freespace / 1024 / 1024 / 1024)


But this:

Convert(Decimal(2,1),tblDiskdrives.Size / 1024 / 1024 / 1024)


Causes Error: Expression evaluation caused an overflow. [ Name of function (if known) = ]
1 ACCEPTED SOLUTION
RCorbeil
Honored Sweeper II
Probably because you got lucky and only had small values of Freespace.

Try the function manually and you'll find that
Convert(Decimal(2,1), 9.94)
will produce 9.9, but
Convert(Decimal(2,1), 9.95)
will produce as overflow error. Allow a larger value
Convert(Decimal(3,1), 9.95)
and the result is 10.0.

Is there a particular reason why you want to restrict display output to values < 10? If you're just wanting to display the value with one decimal place, consider replacing the size parameter (2 in your example) with something much larger than you're ever likely to see. I believe the default is Decimal(18,0), so why not just specify Decimal(18,1) to get the one decimal you seem to be after? That would cover you up to 99,999,999,999,999,999.94.

View solution in original post

2 REPLIES 2
Juha_Otava
Engaged Sweeper III
Thanks, it was that simple. I was creating a report showing workstation less than 5 GB disk free and wanted to show GB instead of bytes. 18,1 works just like I needed.
RCorbeil
Honored Sweeper II
Probably because you got lucky and only had small values of Freespace.

Try the function manually and you'll find that
Convert(Decimal(2,1), 9.94)
will produce 9.9, but
Convert(Decimal(2,1), 9.95)
will produce as overflow error. Allow a larger value
Convert(Decimal(3,1), 9.95)
and the result is 10.0.

Is there a particular reason why you want to restrict display output to values < 10? If you're just wanting to display the value with one decimal place, consider replacing the size parameter (2 in your example) with something much larger than you're ever likely to see. I believe the default is Decimal(18,0), so why not just specify Decimal(18,1) to get the one decimal you seem to be after? That would cover you up to 99,999,999,999,999,999.94.