开发者

Rounding off and storing just that value for currency

What is the way to round off a variable and store it rounded off so that if it goes to DB, it goes off exactly as it was being displayed.

For example, in calculating a total for a order after taxes, etc.., while it is displaying just two digits to the user like 12.67, it was actually being stored in the database unrounded.

Right now, I am working around it by doing String.Format("{0:f2", total) and then converting it back to double and then use it to display/store in DB, but there's gotta be a better way.

I saw in an example code like this

prot开发者_如何学Pythonected override void OnModelCreating(
    System.Data.Entity.ModelConfiguration.ModelBuilder modelBuilder) {
    modelBuilder.Entity<Movie>().Property(p => p.Price).HasPrecision(18, 2);
}

Is there a way to do that precision setting without using entity?

I am using custom built classes for business objects, maybe there is an annotation that I would be able to use?


Here you go http://msdn.microsoft.com/en-us/library/ms131275.aspx. There are several overloads so you can choose the best fit for your need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜