c# - How to display output in the same culture that was entered using "double.Parse(str, CultureInfo.InvariantCulture);"? -
i'm pretty new c#
, .net
, programming on windows in general. here code:
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.globalization; namespace myapp { class program { static void main(string[] args) { string linebreak = "\r\n"; string str = console.readline(); double number = double.parse(str, cultureinfo.invariantculture); console.writeline("you've entered: " + number + linebreak + "variable type:" +number.gettype()); console.writeline("press key exit . . ."); console.read(); } } }
if enter double
"32,45"
(notice there comma separator), output this:
you've entered: 32,45 variable type: system.double
but when enter double
variable "32.45"
(notice, there dot instead of comma), output this:
you've entered: 32,45 variable type: system.double
it's same. know because of cultureinfo set on local machine.
how can make kind of independent(not changing settings or stuff, in code? when user opens program, shouldn't change in settings)?
like when type dot outputs double dots , when type comma displays comma?
best regards, pāvels.
Comments
Post a Comment