I’m trying to format a float as currency, but so far have run into errors with what I would normally use in python. Locale.currency produces a type error and using “:.2f” doesn’t seem to work. I want to have the “Amount” column formatted as “$123.00” or “$12.53”. The State.results is a basic session.query. Any ideas?
Here’s the code.
class Accounts(rx.Model, table=True):
id: Optional[int] = Field(primary_key=True)
Name: str
Number: int
ID: str
Amount: float
def show_account(row: Accounts):
return rx.table.row(
rx.table.cell(row.Name),
rx.table.cell(row.Number),
rx.table.cell(row.ID),
rx.table.cell(row.Amount),
)
def index():
return rx.fragment(
rx.table.root(
rx.table.header(
rx.table.row(
rx.table.column_header_cell("Name"),
rx.table.column_header_cell("Number"),
rx.table.column_header_cell("ID"),
rx.table.column_header_cell("Amount"),
)
),
rx.table.body(
rx.foreach(State.results, show_account),
),
),
)