ZSQL Method's Precision
Hi: In a PostgreSQL DB I have a Numeric data type with a precision of two decimal places. If I have 1.33 in as the result from my query, it's everything is good. However, if I have 1.30 it reduces the precision to one decimal place and I get 1.3. Not so good when dealing with currency ( I don't want to use the money data dype ). Any ideas on how I can get my ZSQL method to keep two decimal places? Thanks, Jason. -- ........................................ .... Jason C. Leach .... PGP Key: 0x62DDDF75 .... Keyserver: gpg.mit.edu
Jason C. Leach wrote:
Hi:
In a PostgreSQL DB I have a Numeric data type with a precision of two decimal places. If I have 1.33 in as the result from my query, it's everything is good. However, if I have 1.30 it reduces the precision to one decimal place and I get 1.3. Not so good when dealing with currency ( I don't want to use the money data dype ).
Any ideas on how I can get my ZSQL method to keep two decimal places?
Thanks, Jason.
1.3 and 1.30 are different only in terms display and printing. One approach can be wrapping your calls to the zsql in a python script that applies formatting before returning the relavent results. res = yourZSQL(params or request is all set up) return "$%.2f" % res[0].yourAmountThatYouNeedToFORMAT
In a PostgreSQL DB I have a Numeric data type with a precision of two decimal places. If I have 1.33 in as the result from my query, it's everything is good. However, if I have 1.30 it reduces the precision to one decimal place and I get 1.3. Not so good when dealing with currency ( I don't want to use the money data dype ).
Any ideas on how I can get my ZSQL method to keep two decimal places? As others said it's a matter of displaying. You say that you don't want to use money datatype but keep in mind that postgre adapter is able to use Python's Decimal datatype for money values (in python2.3 you need additional module decimal.py from Python 2.4 to enable it) which may give you necessary precision for financial operations and is able to store really big numbers.
-- Maciej Wisniowski
Maciej Wisniowski schrieb:
In a PostgreSQL DB I have a Numeric data type with a precision of two decimal places. If I have 1.33 in as the result from my query, it's everything is good. However, if I have 1.30 it reduces the precision to one decimal place and I get 1.3. Not so good when dealing with currency ( I don't want to use the money data dype ).
Any ideas on how I can get my ZSQL method to keep two decimal places? As others said it's a matter of displaying. You say that you don't want to use money datatype but keep in mind that postgre adapter is able to use Python's Decimal datatype for money values (in python2.3 you need additional module decimal.py from Python 2.4 to enable it) which may give you necessary precision for financial operations and is able to store really big numbers.
The adaptor should use it for numeric data as well (hey, hence the name ;) Use of the deprecated money datatype in postgres isnt recommended. (And its superceeded by numeric anyway) Regards Tino Wildenhain
participants (4)
-
David H -
Jason C. Leach -
Maciej Wisniowski -
Tino Wildenhain