Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)

I want to put a negative sign before the dollar sign, For example, the below output is positive:

paste0("$ ",formatC(2344, format="f", digits=2, big.mark=","))

[1] "$ 2,344.00"

However, if the number is negative, dollar symbol will come before that:

paste0("$ ",formatC(-2344, format="f", digits=2, big.mark=","))

[1] "$ -2,344.00"

But I want the output as:

> paste0("$ ",formatC(-2344, format="f", digits=2, big.mark=","))

[1] "- $ 2,344.00"

1 Answer

0 votes
by (108k points)

I think you can use the scales::dollar() in R programming:

scales::dollar(2344)

#[1] "$2,344"

scales::dollar(-2344)

#[1] "-$2,344"

Browse Categories

...