将数字格式设置为右对齐,同时保持货币符号左对齐
是否有内置的 FormatString 或使用自定义 FormatString 的方法:
$150.00
$1,170.00
$12,170.00
$90.00
$38.00
$750.00
并将它们格式化为:
$ 150.00 $ 1,170.00 $ 12,170.00 $ 90.00 $ 38.00 $ 750.00
不知道最大值?这是在 gridview 绑定列中 我目前位于 rowdatabound 的代码隐藏中,循环遍历现有行以获取最大的行,并在必要时更改当前行,或者如果当前行是最大的则更改现有行,所以我有一种解决方法,但希望有一个干净的解决方案。
Is there a built in FormatString or a way to use a custom FormatString to take:
$150.00
$1,170.00
$12,170.00
$90.00
$38.00
$750.00
And format them like:
$ 150.00 $ 1,170.00 $ 12,170.00 $ 90.00 $ 38.00 $ 750.00
without knowing the largest value? This is in a gridview boundcolumn
I am currently in the codebehind on rowdatabound looping through the existing rows to get the largest and changing the current one if necessary or changing the existing ones if the current one is the largest, so I have a workaround but was hoping for a clean solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,如果不知道最大长度,就无法用空格填充字符串,并且要获得最大长度,您需要知道最大值。
您是否考虑过在列上使用对齐属性?您将得到以下内容,这并不完全是您正在寻找的内容。
To the best of my knowledge, there is no way to pad a string with spaces without knowing the maximum length and to get the maximum length you would need to know the maximum value.
Have you considered the use of an alignment property on the column? You would get the following, which is not quite exactly what you are looking for.
如果您有数字,并且货币相同,为什么不在网格中使用模板列,让一个跨度随货币向左浮动,一个跨度随金额向右浮动。可以省去很多麻烦...
If you have the numbers, and the currency will be the same, why not just use a template column in your grid, have a span floated left with the currency and a span floated right with the amount. Could save a lot of hassle...