@@ -14,8 +14,7 @@ public static void ValidationAllow()
1414 Price = 100_000.00m ,
1515 Price2 = 0.01m ,
1616 Price3 = 1_000_000_000_000_000 , // no error, is wrong!
17- Price33 = 1_000_000_000_000_000 , // no error, is wrong!
18- Price4 = 999_999_999_999_999.99981m // no error
17+ Price4 = 999_999_999_999_999.99981m // no error, is right
1918 } ;
2019 var context = new ValidationContext ( product ) ;
2120 var results = new List < ValidationResult > ( ) ;
@@ -38,8 +37,10 @@ public static void ValidationError()
3837 Price = - 1.00m ,
3938 Price2 = 0.001m ,
4039 Price3 = 999_999_999_999_999.99991m , // no error, is wrong!
41- Price33 = 999_999_999_999_999.99991 , // no error, is wrong!
42- Price4 = 999_999_999_999_999.99991m // error
40+ Price4 = 999_999_999_999_999.99991m , // error, is right
41+ Price5 = 999_999_999_999.99991 , // no error, is wrong!
42+ Price55 = 999_999_999_999.99991 , // no error, is wrong!
43+ Price555 = 999_999_999_999.99991 , // error, is right
4344 } ;
4445 var context = new ValidationContext ( product ) ;
4546 var results = new List < ValidationResult > ( ) ;
@@ -53,6 +54,10 @@ public static void ValidationError()
5354 Console . WriteLine ( $ "{ string . Join ( ',' , error . MemberNames ) } : { error . ErrorMessage } ") ;
5455 }
5556 }
57+ //Price : 价格必须在0.01到100,000.00之间
58+ //Price2 : The field Price2 must be between 0.01 and 100000.00.
59+ //Price4 : The field Price4 must be between 0.0001 and 999999999999999.9999.
60+ //Price555 : The field Price555 must be between 0.0001 and 999999999999.9998.
5661 }
5762
5863 #endregion
@@ -73,12 +78,18 @@ public class Product
7378 [ Range ( 0.0001 , 999_999_999_999_999.9999 ) ] // Range参数只有double,所以不能超过 double 有效位数,between 0.0001 and 1000000000000000
7479 public decimal Price3 { get ; set ; }
7580
76- [ Range ( typeof ( double ) , 0.0001 , 999_999_999_999_999.9999 ) ] //
77- public double Price33 { get ; set ; }
78-
7981 [ Range ( typeof ( decimal ) , "0.0001" , "999999999999999.9999" ) ] // decimal Range条件需要使用string参数,避免double精度问题
8082 public decimal Price4 { get ; set ; }
8183
84+ [ Range ( 0.0001 , 999999999999.9999 ) ]
85+ public double Price5 { get ; set ; }
86+
87+ [ Range ( typeof ( double ) , "0.0001" , "999999999999.9999" ) ]
88+ public double Price55 { get ; set ; }
89+
90+ [ Range ( typeof ( double ) , "0.0001" , "999999999999.9998" ) ]
91+ public double Price555 { get ; set ; }
92+
8293 #endregion
8394 }
8495}
0 commit comments