javaScript中超过int的最大范围

javaScript中超过int的最大范围

直接po图片和代码

如下图:大家有没有想过,在javaScript中,如果我们要保存一个超大的整数,该如何做呢?这是我心血来潮想到的一个问题?欢迎大家留言,不吝赐教!

下面是源代码,testInt.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>测试超过int的最大范围</title>
<style type="text/css">
input {
	/*文本框样式*/
	/*border:2px solid blue;*/
	/*这是简易写法,这样写语法是合理的,而且可以可以节省时间,如果不省略,border具体对应的属性写法如下:*/
	font-size: 25px;
	border-radius: 6px; /*把边框做成圆角*/
	border-width: 2px;
	border-style: solid;
	border-color: #4B0082;
}

input[type=text], input[type=password] {
	width: 600px;
	height: 32px;
	font-size: 20px;
	border: 2px solid #8E388E;
	border-radius: 4px; /*设置边框的4个直角变成圆角有弧度*/
	font-weight: bold; /*文本框中的文本字体加粗*/
	color: #0000a0;
	background-color: #ffff9f;
}

input[type=button], input[type=submit], input[type=reset], button {
	background-color: #8E388E;
	border-radius: 3px;
	border: none;
	padding: 6px 8px;
	color: #fff;
	font-size: 14px;
	overflow: visible;
	cursor: pointer;
	margin: 0px;
	line-height: normal;
	box-sizing: border-box;
	display: inline-block;
	text-align: center;
	vertical-align: middle;
	/*width:360px;*/
	/*height: 50px;*/
}
</style>
<script type="text/javascript">

	var jsonObj = {"userName":"ja\"\"ck"};
	console.log(jsonObj.userName);
	
	var testInt = 999999999999999999999999999;
	var testInt2 = 99;
	
	window.onload = function() {
		
	}
	
	function setInputNodeValue1(){
		$("number1").value = testInt;
	}
	
	function setInputNodeValue2(){
		$("number2").value = testInt + 100;
	}
	
	function setInputNodeValue3(){
		$("number3").value = testInt2;
	}
	
	function setInputNodeValue4(){
		$("number4").value = testInt2 + 100;
	}
	
	function setInputNodeValue5(){
		$("number5").value = testInt - 999999999999999999999999995;
	}
	
	function setInputNodeValue7(){
		$("number7").value = testInt - 9999999999999999995;
	}
	
	function $(id){
		var obj = document.getElementById(id);
		return obj;
	}

</script>
</head>
<body>
<h1>测试超过int的最大范围</h1>
<input type="button" value="给文本框1赋值" onclick="setInputNodeValue1()">
文本框1:<input type="text" id="number1"><br/><br/>
<input type="button" value="给文本框2赋值" onclick="setInputNodeValue2()">
文本框2:<input type="text" id="number2"><br/><br/>
<input type="button" value="给文本框3赋值" onclick="setInputNodeValue3()">
文本框3:<input type="text" id="number3"><br/><br/>
<input type="button" value="给文本框4赋值" onclick="setInputNodeValue4()">
文本框4:<input type="text" id="number4"><br/><br/>
<input type="button" value="给文本框5赋值" onclick="setInputNodeValue5()">
文本框5:<input type="text" id="number5"><br/><br/>
<div style="background-color: #7CCD7C; height: 60px;border:2px solid green;">
<form action="${pageContext.request.contextPath}/TestInt" method="get">
文本框6:
<input type="text" id="number6" name="number6" value="999999999999999999999999999" size="30">
<input type="submit" value="提交到servlet">
</form>
</div>
<br/>
<input type="button" value="给文本框7赋值" onclick="setInputNodeValue7()">
文本框7:<input type="text" id="number7"><br/><br/>
</body>
</html>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值