這對我來說似乎有點問題。零字符串消失。 - C#
隨着我的項目,每當我輸入一個decimal
值如2.12
,並且我調用一個函數驗證其他點並返回一個string
。
現在,我Add
這個十進制值在List<string>
命名爲UserValues
。
但是,當我輸入一些值爲0.15時,相同的函數返回0.15
。但是當我Add
它到UserValues
它將它存儲爲0.15,這與客戶要求相矛盾。 或者如果我輸入值爲0.00
,那麼它存儲一個empty string
。
我需要將值存儲爲,因爲它們是。
任何提示?
謝謝!
編輯:
private string GetContent(
NumericUserVariable templateNumericUserVariable,
double doubleValue,
CultureInfo cultureInfo)
{
string placeholder = "#";
if (!templateNumericUserVariable.IsDecimal)
{
return doubleValue.ToString();
}
string decimalPlaces = placeholder;
if (templateNumericUserVariable.DecimalPlace > 0)
{
decimalPlaces = decimalPlaces.PadRight(
// templateNumericUserVariable.DecimalPlace - 1,
templateNumericUserVariable.DecimalPlace, '#');
return doubleValue.ToString(placeholder + "." + decimalPlaces, cultureInfo);
}
return doubleValue.ToString(placeholder, cultureInfo);
}
我發佈的方法返回了我以字符串格式輸入的值,這是正確的。問題是當我將這個返回值添加到列表。 –
@GrowWithWPF我覺得很難相信。將一個字符串添加到「List」不應該導致字符從字符串中刪除。你確定你確實在觀察從'GetContent()'方法返回的值,而不是'doubleValue'的值嗎? –
JLRishe
@all - 我已經檢查了代碼。在添加到列表中時,我正在調用Add()中的函數。我會嘗試一些排列和組合,如果它不起作用,它會回到這裏。 –