简体   繁体   中英

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? if the second case, how to make the textbox only allow numbers with "," or "." and just 2 digits after the comma or point?

Hope my questions are clear!

It sounds like you need a style for your 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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