简体   繁体   English

如何使用WPF C#和Ado.Net数据实体将十进制值插入货币数据类型列

[英]How to insert a decimal value to money data type column with wpf C# and Ado.Net Data Entity

I'm trying to save prices for products from a textbox. 我正在尝试通过文本框节省产品价格。 I know I have to convert or parse the input into decimal datatype. 我知道我必须将输入转换或解析为十进制数据类型。 Now I have two question about this: 现在我有两个问题:

  1. How to make the output format (when it shows the price in the datagrid) fit my need, to show only two digits after the "," or "."? 如何使输出格式(当它在数据网格中显示价格时)适合我的需要,在“,”或“。”之后仅显示两位数?
  2. what's the best way to set the price with cents? 用美分定价的最佳方法是什么? to make 2 textboxes and concat them somehow or set it manually from just 1 textbox? 制作2个文本框并以某种方式合并它们还是仅从1个文本框中手动设置? if the second case, how to make the textbox only allow numbers with "," or "." 如果是第二种情况,如何使文本框仅允许带有“,”或“。”的数字。 and just 2 digits after the comma or point? 逗号或点后仅2位数字?

Hope my questions are clear! 希望我的问题清楚!

It sounds like you need a style for your TextBoxes. 听起来您需要TextBoxes的样式。 Here's a basic style that should provide you with enough information to research the terms included so you can alter it to act how you want. 这是一种基本样式,应为您提供足够的信息来研究所包含的术语,以便您可以根据自己的意愿进行更改。 You may need to bind a Path. 您可能需要绑定路径。

<Style x:Key="MoneyStyle" TargetType="{x:Type TextBox}">
    <Setter Property="Text" Value="{Binding StringFormat='###,###.##'"/>
</Style>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM