Maya
Maya

Reputation: 579

Change format of numbers without making number of class chr

In Spain the format for numbers is for example: 4.000.000,25 (4 million and 1/4). Is there a way to change the format of numbers (preferably for the whole R project) without it being changed to characters?

Right now I preform a function on all my dataframes. Function looks like:

fnx = function(x){print(formatC(x, format = "d", big.mark = ".", decimal.mark = ","), quote=F)}
fnx(567*4325)
# 2.452.275

class(fnx(567*4325))
# "character"

Is there another way? And a way to not transform it to a character class?

Upvotes: 3

Views: 108

Answers (1)

akrun
akrun

Reputation: 887108

We could use comma from formattable

out <- formattable::comma(567*4325, big.mark = ".", decimal.mark = ",")
out
#[1] 2.452.275,00

-check the class

is.numeric(out)
#[1] TRUE

Upvotes: 5

Related Questions