Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ==> _RoundDecimal($NbDouble, $NbForRound)
- ; This function takes two parameters:
- ; $NbDouble to take the number to be rounded. Datatype is double.
- ; $NbForRound to contain the precision of the rounding. Datatype is int
- ; This function return a variable of datatype double or int if rounding is zero or an @error code.
- ; @error:
- ; 1 => $NbDouble isn't number
- ; 2 => $NbForRound isn't integer
- ; 3 => $NbForRound ins't positive number.
- Func _RoundDecimal($NbDouble, $NbForRound)
- ; If $NbDouble isn't double datatype.
- If IsFloat($NbDouble) <> 1 Then
- If IsNumber($NbDouble) = 1 Then
- Return $NbDouble
- Else
- SetError(1)
- Return
- EndIf
- EndIf
- ; If $NbToRound isn't integer datatype.
- If IsInt($NbForRound) <> 1 Then
- SetError(2)
- Return
- EndIf
- ; If $NbToRound isn't a positive number
- If $NbForRound <= 0 Then
- SetError(3)
- Return
- EndIf
- ; We transform $NbDouble in string to separate iteger part to decimal part
- Local $StringNbDouble = String($NbDouble)
- $StringNbDouble = StringSplit($StringNbDouble,".")
- Local $LenghtOfDoublePart = StringLen($StringNbDouble[2])
- ; If the number of char to keep is greater than the real lenght of string.
- If $NbForRound >= $LenghtOfDoublePart Then
- Return $NbDouble
- EndIf
- $StringNbDouble[2] = StringLeft($StringNbDouble[2], $NbForRound)
- Local $Result = Number($StringNbDouble[1] & "." & $StringNbDouble[2])
- Return $Result
- Return
- EndFunc
- ; <== _RoundDecimal($NbDouble, $NbForRound)
- ; ==> _NbAfterDecimalPoint($NbDouble)
- ; This function takes one parameter:
- ; $NbDouble to take the number to be rounded. Datatype is double.
- ; This function return a variable of datatype int and contain the number of number after decimal point.
- ; @error:
- ; 1 => $NbDouble isn't number
- Func _NbAfterDecimalPoint($NbDouble)
- If IsFloat($NbDouble) <> 1 Then
- If IsNumber($NbDouble) = 1 Then
- Return $NbDouble
- Else
- SetError(1)
- Return
- EndIf
- EndIf
- Local $StringNbDouble = String($NbDouble)
- $StringNbDouble = StringSplit($StringNbDouble,".")
- Local $LenghtOfDoublePart = StringLen($StringNbDouble[2])
- Return Int($LenghtOfDoublePart)
- EndFunc
- ; <== _NbAfterDecimalPoint($NbDouble)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement