ASP.net 核心格式属性显示小数点后8位
Format attribute to display 8 decimal places in ASP.net core
我想将我的 latitude
和 longitude
显示到小数点后 8 位。但是,我现在默认只将它显示到小数点后两位。我应该如何更改模型?
型号:
public class LocationModel
{
[Display(Name = "Latitude")]
public decimal Latitude { get; set; }
[Display(Name = "Longitude")]
public decimal Longitude { get; set; }
}
两个选项:
- DataFormatString
public class LocationModel
{
[Display(Name = "Latitude")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:G8}")]
public decimal Latitude { get; set; }
[Display(Name = "Longitude")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:G8}")]
public decimal Longitude { get; set; }
}
- 数学
public class LocationModel
{
private decimal _latitude;
private decimal _longitude;
[Display(Name = "Latitude")]
public decimal Latitude
{
get
{
return Math.Round(_latitude, 8);
}
set
{
this._latitude = value;
}
}
[Display(Name = "Longitude")]
public decimal Longitude
{
get
{
return Math.Round(_longitude, 8);
}
set
{
this._longitude = value;
}
}
}
我想将我的 latitude
和 longitude
显示到小数点后 8 位。但是,我现在默认只将它显示到小数点后两位。我应该如何更改模型?
型号:
public class LocationModel
{
[Display(Name = "Latitude")]
public decimal Latitude { get; set; }
[Display(Name = "Longitude")]
public decimal Longitude { get; set; }
}
两个选项:
- DataFormatString
public class LocationModel
{
[Display(Name = "Latitude")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:G8}")]
public decimal Latitude { get; set; }
[Display(Name = "Longitude")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:G8}")]
public decimal Longitude { get; set; }
}
- 数学
public class LocationModel
{
private decimal _latitude;
private decimal _longitude;
[Display(Name = "Latitude")]
public decimal Latitude
{
get
{
return Math.Round(_latitude, 8);
}
set
{
this._latitude = value;
}
}
[Display(Name = "Longitude")]
public decimal Longitude
{
get
{
return Math.Round(_longitude, 8);
}
set
{
this._longitude = value;
}
}
}