c# - Regional decimal seperator input -
computers in country not accept decimals '.' accept ','
how write program accept 12.5 console decimal number?
use cultureinfo
. if sure using decimal dot standard in country use country's cultureinfo
. can check if is.
// change kk-kz culture code decimal dec = decimal.parse(str, new cultureinfo("kk-kz"));
or can use invariantculture
, numberstyles.any
:
decimal dec = decimal.parse(str, numberstyles.any, cultureinfo.invariantculture);
i implement second 1 don't know from.
here in console application , works me:
public static void main() { string str; str = console.readline(); decimal dec = decimal.parse(str, numberstyles.any, cultureinfo.invariantculture); double db = double.parse(str, numberstyles.any, cultureinfo.invariantculture); console.writeline(dec.tostring("f2", cultureinfo.invariantculture)); console.writeline(db.tostring("f2", cultureinfo.invariantculture)); return; }
Comments
Post a Comment