[英]I need to store the value to variable with int type but int is not enough?
I had Started a new project for school Called BasesConvertor with Java in android app我在 android 应用程序中使用 Java 为学校启动了一个名为 BasesConvertor 的新项目
So My problem is: - to convert Base 10 To an other bases I need to store the value to variable with int type but int is not enough Max int size is : 2,147,483,647所以我的问题是: - 将基数 10 转换为其他基数,我需要将值存储为 int 类型的变量,但 int 不够最大 int 大小为:2,147,483,647
In this case, 72057594037927702
is too long for int
and long
.在这种情况下,
72057594037927702
对于int
和long
。 You will have to use BigInteger
:您将不得不使用
BigInteger
:
BigInteger i = new BigInteger("72057594037927702");
EDIT:编辑:
If you want to use mathematical operations such as addition, subtraction, multiplication, division, etc. you will need to use the predefined methods in the BigInteger
class:如果要使用加、减、乘、除等数学运算,则需要使用
BigInteger
类中的预定义方法:
BigInteger i = new BigInteger("72057594037927702");
System.out.println(i);
// Add five
i = i.add(new BigInteger("5"));
System.out.println(i);
// Take tree
i = i.subtract(new BigInteger("3"));
System.out.println(i);
// Four times
i = i.multiply(new BigInteger("5"));
System.out.println(i);
// Divided among 2
i = i.divide(new BigInteger("2"));
System.out.println(i);
/*
* Output:
* 72057594037927702
* 72057594037927707
* 72057594037927704
* 360287970189638520
* 180143985094819260
*/
you can try storing the value in a different data type, say double would do and check out this chart it might help您可以尝试将值存储在不同的数据类型中,说 double 可以做并查看此图表它可能会有所帮助
http://cs-fundamentals.com/java-programming/java-primitive-data-types.php http://cs-fundamentals.com/java-programming/java-primitive-data-types.php
This chart has all the data types and their limits此图表包含所有数据类型及其限制
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.