Open huifer opened 4 years ago
System.out.printf("%.2f", 1.323);
console1.32
1.32
I use @JSONField(format = "%.2f") for Double &String &Float& BigDecimal
@JSONField(format = "%.2f")
Double
String
Float
BigDecimal
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.annotation.JSONField; import lombok.Data; import lombok.NoArgsConstructor; import java.math.BigDecimal; @Data @NoArgsConstructor public class RunTest { @JSONField(format = "%.2f") private Double d0; @JSONField(format = "%.2f") private String d1; @JSONField(format = "%.2f") private Float d2; @JSONField(format = "%.2f") private BigDecimal d3; public static void main(String[] args) { System.out.printf("%.2f", 1.323); RunTest runTest = JSON.parseObject("{\n" + " \"d0\": 1.323,\n" + " \"d1\":1.323,\n" + " \"d2\": 1.323,\n" + " \"d3\":1.323\n" + "}", RunTest.class); } }
I hope value is 1.32 What should I do?
maybe don't have the method ,you can try to use deserializeUsing and write your own deserialize class
console
1.32
I use
@JSONField(format = "%.2f")
forDouble
&String
&Float
&BigDecimal
I hope value is
1.32
What should I do?