修剪小数点中的零
如果多余的零没有任何小数值,我想删除它们。但如果他们有的话,我想向他们展示。
在图片中,我想从 10.00 和 20.00 中提高不必要的 0。但我想显示下面的其他 3 条记录。
我使用c#、asp.net 4.0和GridView来显示.
I would like to remove the extra zeros if they don't have any decimal values. But if they have, I would like to show them.
In the picture, I want to height the unnecessary 0 from the 10.00 and 20.00. But I want to show the other 3 records below.
I used c#, asp.net 4.0 and GridView to display .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
尝试
Try
如果您对格式有疑问 Kathy Kam 的 .NET 格式字符串 101 是您的终极资源。
If you have trouble with formats Kathy Kam's .NET Format String 101 is ultimate resource for you.
我看不到图片,但听起来您只需要一个格式字符串:如果需要,
#
字符代表一个数字,0
字符代表您总会有一个数字。因此"#.##"
的格式字符串听起来可能就是您所需要的。I can't see the picture, but it sounds like you just need a format string: The
#
character represents a digit if it's needed, and a0
character represents that you'll always have a digit. So a format string of"#.##"
sounds like it might be what you need.我相信“#”自定义格式字符可能适合您。查看 MSDN 上的“自定义数字格式字符串”:
http://msdn .microsoft.com/en-us/library/0c899ak8.aspx
您需要在 GridView 配置中的某处指定列的“格式”。
I believe the "#" custom format character might work for you. Take a look at the "Custom Numeric Format Strings" on MSDN:
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx
You will need to specify the "Format" for the column somewhere in your GridView configuration.
你总是可以按照程序员的方式去做。
定义一个作为标签的 TemplateField,其 Text 属性的绑定如下:
Text='<%# WeightText( Container.DataItem ) %>'
。在后面的代码中定义 WeightText 方法,该方法将 Container.DataItem 作为参数。
You could always go at it the programmers way.
Define a TemplateField that is a label and its Text property is bound like so:
Text='<%# WeightText( Container.DataItem ) %>'
.Define the WeightText method in the code behind that takes the Container.DataItem as a parameter.