Does Julia provide a simple way to use decimal commas instead of the standard point?
Some countries use that standard and working with local data is sometimes a hassle. For example, importing spreadsheets with percentage numbers would require users to import the string, convert commas into dots, then use parse to get the proper float variable.
The biggest issue for me is for making tables and graphs. Other tools allow you to set some localization variable which will write variables as appropriate, so an internally stored ā2.5ā can be shown as ā2,5ā in such situation.
The UInt8(',') above used to be UInt8('.') in the original.
This carries some risk though, since you donāt know if anything else depends on the expected/default printing, and will silently (or loudly) break. You could also define your own function for printing decimals with commas, either based on the above or custom, and use it when you need it. I.e. when making labels for graphs and tables, use your new function to create the strings.
If this is a must-have for you, you could open an issue on github. Maybe someone who knows more can figure out if making this possible breaks anything important.
I thought I had answered before, but apparently something came up. Iām glad to know a solution exists, but itās a bit sad thereās no simple ālocale flagā to set either as default. That said, there would still need additional work for the Plots side of things.
@jling thanks for pointing out CSV.jl. It can probably solve the problem of writing into files with the appropriate limiter, but it certainly doesnāt solve showing in Julia REPL and plotting a graph with decimal commas.
I like the simplicity of this approach for dealing with tables, unless Julia has functionality which takes a matrix of elements and automatically turns them into a LaTeX table (which Iām almost sure it does). This may be solved by first translating an array of an arbitrary type into a properly formatted string.
A similar workaround may be possible with Plots. Maybe I can override the current print function to use decimal commas for my environment.
Iām not aware of any such module for Julia, in a package, nor as a stdlib, but there is for dates (in the docs): ācustom locales can be loaded by passing in the locale=>Dict{String,Int} mapping to the MONTHTOVALUEABBR and MONTHTOVALUE dicts for abbreviated and full-name month names, respectively.ā
Fyi, using Masonās ReplMaker.jl we can get an interesting REPL with minimal effort, which accepts as input the decimal comma as decimal separator and the point as thousands separator. (Not exactly the OP requirement, but at least it can help to check the grocery cost-of-living.)
using ReplMaker
comma2point(str) = Meta.parse(replace(str, r"[-?0-9]{1,3}(.[0-9]{3})*(\,[0-9]+)?" => s -> replace(s, "."=>"", ","=>".")))
initrepl(comma2point,
prompt_text="decimal-commas> ",
prompt_color=:blue,
start_key=',',
mode_name="decimal-comma"
)
# Type comma `,` in the REPL to start (may need backspace first):
decimal-commas> 11.123,337 + 456,5 + 5.400 # 16979.837
decimal-commas> x = [11.123,337, 456,5, 5.400] # 3-element Vector{Float64}
decimal-commas> using Statistics
decimal-commas> (sum(x), mean(x), std(x)) # (16979.837, 5659.95, 5338.17)