• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

OverFlow Error

I need to store decimal point values in a variable, the range of values is 19.999999 to 0.999999...

The problem is what type do I declare my variable as because....

Integer and Long no good as it rounds decimal places...

Decimal has a range of "For numbers with 28 decimal places, the range is
+/-7.9228162514264337593543950335. The smallest possible non-zero number is 0.0000000000000000000000000001."

Single has a range of "-3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values."
 
Variant is the same as "Same range as Double for numerics."  

Thanks Ian

0
ISC
Asked:
ISC
  • 4
  • 2
  • 2
  • +1
1 Solution
 
GrahamSkanCommented:
You can store the numbers 19.999999 to 0.999999... in doubles. How many significant digits (how accurate) do you need?
0
 
ISCAuthor Commented:
At least 2 significant digits and 6 decimal places...

I tried this but I get an overflow error...


Ian
0
 
ISCAuthor Commented:
The calculation causing the problem ss...

   Dim k As Double
       
    k = m_objAccrualRecord.m_intNumberOfDays * 100 * l_dblDailyAccrualTotal

This caused an overflow, however if I change the code to...

  Dim k As Double
       
        k = CDbl(m_objAccrualRecord.m_intNumberOfDays) * CDbl(100) * l_dblDailyAccrualTotal

It works....!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
GrahamSkanCommented:
There is a buglet in VB. The calculation can start off assuming (for speed) that it is using integers, only to be confounded later on by a number too big to fit into its temporary location.
0
 
ISCAuthor Commented:
Thanks I did not know that...!
0
 
EDDYKTCommented:
how about


k = l_dblDailyAccrualTotal * 100.0 * m_objAccrualRecord.m_intNumberOfDays
0
 
EDDYKTCommented:
or


k = m_objAccrualRecord.m_intNumberOfDays * 100.0 * l_dblDailyAccrualTotal
0
 
ISCAuthor Commented:
My solution was to use CDbl( ) in the formula this worked and stopped the overflow error...!

 Dim k As Double
       
        k = CDbl(m_objAccrualRecord.m_intNumberOfDays) * CDbl(100) * l_dblDailyAccrualTotal
0
 
RomModCommented:
Question closed - 500 points refunded.

Best regards,
RomMod
Experts Exchange
Community Support Moderator
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now