在 Windows 10 上使用 Convert.ToDouble('Infinity') 避免 FormatException [英] Avoiding FormatException with Convert.ToDouble('Infinity') on Windows 10
问题描述
如何在 Windows 10 上解析Infinity"?我在使用 RowFilter 时遇到了这个问题:例如
How do I parse "Infinity" on Windows 10? I ran into this when using RowFilter: e.g.
rowFilter = "[ColumnName] = 'Infinity'"
此代码适用于 Windows 7/8,但在 Windows 10 上会因 FormatException 而中断.
This code works on Windows 7/8 but breaks on Windows 10 with a FormatException.
推荐答案
无穷大符号是特定于文化的.似乎默认 (us-en) 文化使用的符号在 Windows 8 和 10 之间发生了变化.我不知道如何或是否可以为 RowFilter
指定 InvariantCulture
code> 表达式:它似乎假设 CurrentCulture
.上面的 RowFilter
表达式将与 CurrentCulture
的 PositiveInfinitySymbol
一起使用:
The infinity symbol is culture-specific. It appears the symbol used by the default (us-en) culture changed between Windows 8 and 10. I don't know how or even if it's possible to specify the InvariantCulture
for RowFilter
expressions: it seems to assume CurrentCulture
. The RowFilter
expression above will work with PositiveInfinitySymbol
of CurrentCulture
:
rowFilter = String.Format("[ColumnName] = '{0}'", CultureInfo.CurrentCulture.NumberFormat.PositiveInfinitySymbol)
这篇关于在 Windows 10 上使用 Convert.ToDouble('Infinity') 避免 FormatException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!