Declare variable with NOT rounding numbers

Soundje

Registered User.
Local time
Today, 06:49
Joined
Aug 14, 2014
Messages
27
Hello
i wondering if anybody could help me with this "simple" question:
I need to declare a variable (max_nog_leveren ) but that variable may not be rouded or only after 5 digits so as example 15,xxxxx

I am now using it as a "Integer" but that is not working very well..

Can you help me by telling me what I should be using?

Many thanks,
Koen

Code:
   Dim iRet As Integer
  Dim strPrompt As String
  Dim strTitle As String
  Dim max_nog_leveren As Integer
  Dim strQuery As String
  Dim nettohoeveelheid_toevoegen As String
    
Me.nettogewicht_toevoegen.Value = (Me.hoeveelheid_bruto_toevoegen.Value * Me.RestAfval_tara_toevoegen.Value) / 100
Me.nettogewicht_toevoegen.Value = Me.hoeveelheid_bruto_toevoegen.Value - Me.nettogewicht_toevoegen.Value
    
nettohoeveelheid_toevoegen = Me.nettogewicht_toevoegen.Value
 max_nog_leveren = Me.Hoeveelheid.Value - som_Netto_gewicht_DB ' hoeveelheid nog te leveren tot contract 100% klaar is.
 
The Integer type only takes values between +/- ~2.1bn (32-bit)

If your value could potentially be outside that range, try using Long instead (64-bit, or +/- ~9.2x10^18)
 
I am now using it as a "Integer" but that is not working very well..

By the way, you're not giving us very much information here - what exactly is "not working very well"? Is it taking an unexpected value? Is it raising an error?
 
It looks like you are trying to produce a percentage from your code. If you need numbers after the decimal use:

double

Example:

Dim iRet As Double
 
Thanks a lot everybody..
I used the "double" and that one resolved my issue..

Once more thanks for all tips..
 
The Integer type only takes values between +/- ~2.1bn (32-bit)

If your value could potentially be outside that range, try using Long instead (64-bit, or +/- ~9.2x10^18)

More importantly, Integer (and Long) only hold whole numbers which is the cause of the problem in the case of this question.

Note however that some arithmetic on Double will result in small rounding errors due to the binary nature of computers being unsuited to base ten decimals.

If precision really matters then use Decimal datatype and set the Precision and Scale properties as required.

Currency is another alternative for some cases. It is essentially a Decimal with a fixed Scale that supports four decimal places.
 

Users who are viewing this thread

Back
Top Bottom