3 回答

TA貢獻1801條經(jīng)驗 獲得超8個贊
嘗試在 XAML 中格式化您的雙精度值
<TextBlock Text="{Binding MyDoubleVal, StringFormat=n1}" />
如果只有 Content 屬性,則改用 ContentStringFormat

TA貢獻1865條經(jīng)驗 獲得超7個贊
你有很多選擇。其中一些如下:
字符串.格式():
double a = 18.54657;//some number
Console.WriteLine(string.Format("{0:F2}", a);
// where F2 tells the function to format as a float with 2 decimals... for your usecase you can use F1
雙.ToString():
double a = 18.54657;//some number
Console.WriteLine(a.ToString("#.#");
//where the # after the period tells the function to include 1 number after the period(or 1 decimal point). You can add more # for more decimal points to show. As a side not you can do a.ToString("#,###.#") to add commas to numbers
- 3 回答
- 0 關注
- 228 瀏覽
添加回答
舉報