.net - How do I parse floats and doubles case-insensitively in c# (to cover "infinity", etc.)? -
in locale, double.parse("infinity")
returns double.positiveinfinity
, double.parse("infinity")
throws system.formatexception
. analogous things happen negative infinity , nan.
i use cultureinfo.currentculture.numberformat.positiveinfinitysymbol.equals()
case-insensitive comparison check match before calling double.parse()
(and likewise negative infinity , nan). however, hoping more elegant.
i don't see option beyond doing tryparse()
, and, on failure, special-casing 3 special tokens shown in number.parsedouble()
, double.tryparse()
. i'd check after rather before since, in cases, won't happen.
Comments
Post a Comment