[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
BigDecimal详解:
*
Java在java.math包中提供的API类BigDecimal,用来对超过16位有效位的数进行精确的运算。双精度浮点型变量double可以处理16位有效数。在实际应用中,需要对更大或者更小的数进行运算和处理。float和double只能用来做科学计算或者是工程计算,在商业计算中要用java.math.BigDecimal。BigDecimal所创建的是对象,我们不能使用传统的+、-、
、/等算术运算符直接对其对象进行数学运算,而必须调用其相对应的方法。方法中的参数也必须是BigDecimal的对象。构造器是类的特殊方法,专门用来创建对象,特别是带有参数的对象。
equals方法会比较值和精确度,而compareTo则会忽略精度。
equals源码:
public boolean equals(Object anObject)
{//name2传入equals方法,anObject指向name2,name2是上转型对象
if (this == anObject) {//this代指调用equals方法的name1,name1和name2地址不一样,继续向下运行 return
true; } if (anObject instanceof String) {//此处用于判断name2是否是String类或其子类,此处是,继续运行
String anotherString = (String)anObject;//对象下转型 int n =
value.length;//在编译器中可看出value是全局变量,其前存在省略掉的this(即n = this.value),用于测量name1的长度 if
(n == anotherString.value.length) {//判断name1和name2指向的字符串长度是否相等,此处相等,继续运行 char
v1[] = value;//将name1指向的字符串存入字符数组v1 char v2[] =
anotherString.value;//将name1指向的字符串存入字符数组v2 int i = 0; while (n-- != 0)
{//利用循环,逐字符比对两字符串,若有任何不同,返回false,否则返回true if (v1[i] != v2[i]) return false;
i++; } return true; } } return false; }
以下是java.math.BigDecimal.compareTo()方法的声明
public int compareTo(BigDecimal val)
参数:
val-- 要与此BigDecimal比较的值。
返回值:
此方法,如果BigDecimal为小于val返回-1,如果BigDecimal为大于val返回1,如果BigDecimal为等于val返回0
下面的示例演示math.BigDecimal.compareTo()方法的用法。
public class BigdecimalTest {
public static void main(String[] args) {
BigDecimal z1 = new BigDecimal("0"); BigDecimal z2 = new BigDecimal("0.0");
System.out.println(z1.equals(z2)); System.out.println(z1.compareTo(z2)); }}
输出结果:
1.false
2.0