advice needed re mysql decimal field type
Posted
#1
(In Topic #748)
Regular

Although mysql supports a decimal type, I've never found a way of using it in Gambas.
Any ideas?
Posted
Regular

This then shows as type 'float' in Gambas but is always has only 2 decimal places.
Posted
Expert

Value = Round ( Number [ , Digits ] )
Rounds a number to its nearest integer, if Digits is not specified.
If Digits is specified, rounds to 10 ^ Digits.
Examples
PRINT Round(Pi, -2)
RunPlay
3.14
PRINT Round(1972, 2)
RunPlay
2000
Cheers - Quin.
I code therefore I am
I code therefore I am
Posted
Regular

With accounting and financial projects its important to avoid unwanted fractions of a penny. For this reason I have always used integers to represent money values, dividing by 100 to display the true value. This way there is never a problem with penny fractions.
Recently I've tried the sql DECIMAL(x,y) field. Although Gambas sees the database field (column) as type 'float' an attempt to change the sign of a value (e.g. hResult!DebitValue) results in an error (got STRING, wanted FLOAT). The work around is to move the value into a float variable then change the sign.
Also a simple arithmetic functions on float values throws up fractional penny vales. This is where ROUND helps.
I see there is a functions _DataTypes.SignedDecimal (gb.mysql) but I've no idea how to use it.
1 guest and 0 members have just viewed this.


