Skip to content
Advertisement

Return decimal fields from list

I have a generator which yields to datatype on is decimal and other is string i need the method to just return the decimal

JavaScript

get_amount()

now it is returning [(Decimal(‘1950.00′), ’06/16/2020’), (Decimal(‘4500.00′), ’06/16/2020’)]

I want the list to be returned as formatted how can i do that ‘${:0,.2f}’.format(Decimal(‘1950.00’) which is in my list) so the end result would be like $1,950.00

if the the return has two yields it should return like. $1,950.00, $4,500.00

Advertisement

Answer

Simply get only the first value from your tuple with i[0].

Example:

JavaScript

Output:

JavaScript

Here’s a more verbose version of the for loop, also using str.format instead of f-string

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement