.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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -