Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm building a WPF application. I made my database using Code-First.

I need to insert prices of items in pence (e.g. 500), but when prices will be displayed they should be in pounds (5,00).

I tried to do the "conversion" in the setter of my property

public decimal Price
{
   get { return price; }
   set { price = value/100 ;}
}

But, for some reason, when I drop manually the database, the values in my ListView are shown some times like 0,05 and other times like 500,00. Something must be wrong with this method.

How can I tell my database to consider last 2 numbers of my value as decimal?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
228 views
Welcome To Ask or Share your Answers For Others

1 Answer

You might want to try something like this

public class YourClassName {
   public decimal Price { get; set; }

   [NotMapped]
   public decimal Pounds => Price/100;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...