StringFormat 值为零

编程入门 行业动态 更新时间:2024-10-25 04:14:44
本文介绍了StringFormat 值为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在用 componentart 开发一个 wpf 应用程序,我有一个这样的文本块

I'm developing a wpf application with componentart I have a textblock like this

<TextBlock FontSize="28" Text="{Binding DataPoint.Y, StringFormat=\{0:#\\%\}}" Foreground="Black">

如您所见,我的 StringFormat 在数字后面放了一个 '%' 符号,但是如果我的数据是 0.0(我在后面的代码中填充了组件,我的变量是双精度)我得到了%",但我想要要获得0%",我该怎么做?

As you can see, my StringFormat puts a '%' sign after the number, but if my data is 0.0 (I fill the component in code behind, my variable is a double) I get "%", but I want to get "0%", how can I do this?

推荐答案

您可以使用不同的 StringFormat.而不是 0:# 把 0:0:

you can use different StringFormat. Instead of 0:# put 0:0:

<TextBlock FontSize="28" Text="{Binding Path=MyDouble, StringFormat=\{0:0\\%\}}" Foreground="Black"/>

引用 MSDN:

#:替换#"如果存在,则带有相应数字的符号;否则,结果字符串中不会出现数字.

#: Replaces the "#" symbol with the corresponding digit if one is present; otherwise, no digit appears in the result string.

0:如果有一个,用相应的数字替换零;否则,结果字符串中将出现零.

0: Replaces the zero with the corresponding digit if one is present; otherwise, zero appears in the result string.

更多推荐

StringFormat 值为零

本文发布于:2023-11-02 08:07:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551841.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:值为   StringFormat

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!