I am connecting to AWS redShift DB and fetching records, while I am doing so I use cursor.fetchall() to get list of rows and construct to a Dictionary.
while i do a fetch from RedShift I get decimal values as Decimal(‘1328.10’) since its not if readable format I try to convert it to float while converting to float the zero value is skipped
3.val=float(Decimal(‘1328.10’)) output=1328.1// The zero value is skipped is there any such to retain the value, I don’t want to use the .2f reason I want the result in a numeric not a string.
It would be a great help if you can tell some ideas?
A trailing zero (after the radix point) is meaningless to float types etc. Otherwise an arbitrary number of them could be appended after any float with a finite representation.
Optional trailing zeroes are only meaningful in string representations of floats etc.
Leave it as a Decimal then. That’s what Decimal types are for. I think you have to set the context to 2 d.p.
Or alternatively, like much of the rest of the financial industry’s coders, measure the amount in cents or pennies and use an int instead, and just divide by 100 or whatever, whenever you need to display it.
Business logic is fine, but you will incorrectly implement your requirement: 1328.1(1Cent) 1328.10(10cents) if you use floats, as the business logic requirement is different to the interpretation of those strings both in mathematics, and in all the ISO standards for floats I’ve ever heard of.
Use an int and write some custom string processing logic.
I’m more than happy to provide further help to yourself and anyone else in the financial industry at normal market rates. It won’t take me longer than 15 minutes.
Are you saying your accounting system considers 0.1 and 0.10 to be distinct values? That seems… strange, to say the least. No computer implements this system. Simply put, your requirement (1328.1 and 1328.10 as distinct numerics) cannot be met.