Represent numeric value with typical dollar amount format

后端 未结 4 714
轮回少年
轮回少年 2020-12-03 06:27

I have a data frame storing the dollar amount, it looks like this

> a
  cost
1 1e+05
2 2e+05

I would like it can be shown as this

<
4条回答
  •  心在旅途
    2020-12-03 07:21

    A very simple way is

    library(priceR)
    values <- c(1e5, 2e5)
    format_dollars(values)
    
    # [1] "$100,000" "$200,000"
    

    Notes

    • Add decimal places with format_dollars(values, 2) i.e. "$100,000.00" "$200,000.00"
    • For other currencies use format_currency(values, "€") which gives "€100,000" "€200,000" etc

提交回复
热议问题