Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper data annotation to format my decimal property?

Tags:

I have a POCO with a decimal property called SizeUS. I would like to use data annotations to format the display of the decimal in a view. My SizeUS property is only displaying 2 decimal places in my view and I want it to display 4 decimal places. What is the proper data annotation to accomplish this ?

[DisplayFormat( ? )] public decimal SizeUS {get; set;} 
like image 760
Bill Greer Avatar asked Dec 30 '13 22:12

Bill Greer


People also ask

What data annotation feature allows you to validate a data field that must have a numeric value that falls between specified values?

Range – Enables you to validate whether the value of a property falls between a specified range of values.

How do you use data annotations?

Data annotations (available as part of the System. ComponentModel. DataAnnotations namespace) are attributes that can be applied to classes or class members to specify the relationship between classes, describe how the data is to be displayed in the UI, and specify validation rules.

What are data annotations?

Data annotation is the categorization and labeling of data for AI applications. Training data must be properly categorized and annotated for a specific use case. With high-quality, human-powered data annotation, companies can build and improve AI implementations.

What is data annotation in MVC?

DataAnnotations is used to configure your model classes, which will highlight the most commonly needed configurations. DataAnnotations are also understood by a number of . NET applications, such as ASP.NET MVC, which allows these applications to leverage the same annotations for client-side validations.


1 Answers

[DisplayFormat(DataFormatString="{0:#.####}")] 

See Custom Format Strings for formats and DisplayFormatAttribute for examples

like image 96
Johnbot Avatar answered Sep 24 '22 21:09

Johnbot