当前位置: 首页 > news >正文

做网站需要什么配置的电脑百度网站首页网址

做网站需要什么配置的电脑,百度网站首页网址,上海品划网络做网站,西安专业做网站的js数据精度丢失 最近看面试题想到了之前在开发钟遇到过的问题,现总结一下 在开发过程中,发现从后台返回的数据结构中的id字段在前端显示为不正确的值。经过排查,怀疑是JavaScript中Number类型精度丢失的问题。通过将id字段的类型从Number改为…

js数据精度丢失

最近看面试题想到了之前在开发钟遇到过的问题,现总结一下

在开发过程中,发现从后台返回的数据结构中的id字段在前端显示为不正确的值。经过排查,怀疑是JavaScript中Number类型精度丢失的问题。通过将id字段的类型从Number改为String进行测试,确认了问题的根源。尝试在前端获取数据后立即转换为String类型,但发现数据在JavaScript中接收时精度已经丢失,因此最佳解决方案是让后端将id字段的类型改为String。
在开发的时候,后台返回了一个数据结构如下

const list= [{id: 421234567891234567,name: '数据1'},{id: 421234567891234668,name: '数据2'},{id: 421234567891234679,name: '数据3'},{id: 421234567891234697,name: '数据4'}]
<template><button @click="btn">按钮</button>
</template>
<script setup lang="ts">const num: Array<{ id: number, name: string }> = [{id: 421234567891234567,name: '数据1'},{id: 421234567891234668,name: '数据2'},{id: 421234567891234679,name: '数据3'},{id: 421234567891234697,name: '数据4'}]const btn = () => {console.log('num:', num)}
</script>

通过打印发现数据结果如下图

通过图片发现数据和原始数据不一样了

开始怀疑是数据传输过程造成的,换乘postman 测试发现数据正常

最后怀疑是js在Number类型时精度丢失,于是讲数据换乘String类型测试


<template><button @click="btn">按钮</button>
</template>
<script setup lang="ts">const num1: Array<{ id: string, name: string }> = [{id: '421234567891234567',name: '数据1'},{id: '421234567891234668',name: '数据2'},{id: '421234567891234679',name: '数据3'},{id: '421234567891234697',name: '数据4'}]const btn = () => {console.log('num1:', num1)}
</script>

打印结果如下图

发现确实是Number类型时精度丢失,于是让后端将id改成了String类型

后来想前端能不能解决于是就有了一下的一些尝试

前端获取到数据后就转换一下

<template><button @click="btn">按钮</button>
</template>
<script setup lang="ts">
const num: Array<{ id: number, name: string }> = [{id: 421234567891234567,name: '数据1'
}, {id: 421234567891234668,name: '数据2'
}, {id: 421234567891234679,name: '数据3'
}, {id: 421234567891234697,name: '数据4'
}]const btn = () => {const num2 = num.map((item) => {return {...item, id: item.id.toString()}})console.log('num2', num2)
}
</script>

结果发现不行

最后还实验了别的方法都不行,在js拿到数据的那一刻数据的精度就已经丢失了,最好的方法还是后端去转换

js的数据最大精度为2的53次方 也就是最大只能是9007199254740992

js的数据最小精度为2的-53次方 也就是最大只能是-9007199254740992

js数据范围-9007199254740992~9007199254740992


文章转载自:
http://dinncobowed.tqpr.cn
http://dinncoundesirable.tqpr.cn
http://dinncogalvanize.tqpr.cn
http://dinncotipple.tqpr.cn
http://dinncoproprietress.tqpr.cn
http://dinncoxms.tqpr.cn
http://dinncoskite.tqpr.cn
http://dinncothermit.tqpr.cn
http://dinncosnowplow.tqpr.cn
http://dinncocarbine.tqpr.cn
http://dinncoenhydrous.tqpr.cn
http://dinncoreestablishment.tqpr.cn
http://dinncocongestion.tqpr.cn
http://dinncoexcess.tqpr.cn
http://dinncosonifier.tqpr.cn
http://dinncodrawnet.tqpr.cn
http://dinncoevangel.tqpr.cn
http://dinncoovermike.tqpr.cn
http://dinncopaleosol.tqpr.cn
http://dinncotetrarchate.tqpr.cn
http://dinncodevocalization.tqpr.cn
http://dinncosystem.tqpr.cn
http://dinncooogenesis.tqpr.cn
http://dinncoganoid.tqpr.cn
http://dinncohyte.tqpr.cn
http://dinncoquantification.tqpr.cn
http://dinncouprush.tqpr.cn
http://dinncogenova.tqpr.cn
http://dinncofloodlight.tqpr.cn
http://dinncolvov.tqpr.cn
http://dinncoepb.tqpr.cn
http://dinncodaffydowndilly.tqpr.cn
http://dinncovinification.tqpr.cn
http://dinncooilstone.tqpr.cn
http://dinncomartialize.tqpr.cn
http://dinncoquantification.tqpr.cn
http://dinncosubmission.tqpr.cn
http://dinncocoalman.tqpr.cn
http://dinncovaesite.tqpr.cn
http://dinncoingvaeonic.tqpr.cn
http://dinncoclinical.tqpr.cn
http://dinncomysticize.tqpr.cn
http://dinncoparthenogeny.tqpr.cn
http://dinncotransparence.tqpr.cn
http://dinncotibiofibula.tqpr.cn
http://dinncocole.tqpr.cn
http://dinncoaequorin.tqpr.cn
http://dinncohaemocyte.tqpr.cn
http://dinncobayard.tqpr.cn
http://dinncogorhen.tqpr.cn
http://dinncotalipot.tqpr.cn
http://dinncolaminarin.tqpr.cn
http://dinncoviscometer.tqpr.cn
http://dinncodermatologic.tqpr.cn
http://dinncochauvinist.tqpr.cn
http://dinncoflaxbush.tqpr.cn
http://dinncohoot.tqpr.cn
http://dinncophytoflagellate.tqpr.cn
http://dinncoeuhominid.tqpr.cn
http://dinncoproclamation.tqpr.cn
http://dinncodelegant.tqpr.cn
http://dinncophospholipase.tqpr.cn
http://dinncocubanologist.tqpr.cn
http://dinncodriveway.tqpr.cn
http://dinncoautarky.tqpr.cn
http://dinncotransketolase.tqpr.cn
http://dinncoalcidine.tqpr.cn
http://dinncosolano.tqpr.cn
http://dinncosandburg.tqpr.cn
http://dinncocompurgator.tqpr.cn
http://dinncounregarded.tqpr.cn
http://dinncospontoon.tqpr.cn
http://dinncoadjuvant.tqpr.cn
http://dinncoganoin.tqpr.cn
http://dinncohaggis.tqpr.cn
http://dinncoarbitrational.tqpr.cn
http://dinncospag.tqpr.cn
http://dinncodiversified.tqpr.cn
http://dinncocaspian.tqpr.cn
http://dinncosquash.tqpr.cn
http://dinncocoeval.tqpr.cn
http://dinncoiaru.tqpr.cn
http://dinncoisochromosome.tqpr.cn
http://dinncotrismus.tqpr.cn
http://dinncoacknowledged.tqpr.cn
http://dinncodisconcerted.tqpr.cn
http://dinncothrace.tqpr.cn
http://dinncosternwards.tqpr.cn
http://dinncosentiency.tqpr.cn
http://dinncoconferrer.tqpr.cn
http://dinnconcsa.tqpr.cn
http://dinncoholobenthic.tqpr.cn
http://dinncorubrician.tqpr.cn
http://dinnconightclub.tqpr.cn
http://dinncopunt.tqpr.cn
http://dinncodemiurge.tqpr.cn
http://dinncoprix.tqpr.cn
http://dinncoanbury.tqpr.cn
http://dinncowine.tqpr.cn
http://dinncoarmour.tqpr.cn
http://www.dinnco.com/news/110938.html

相关文章:

  • 局网站建设管理整改情况手机如何做网站
  • 做网站需要用到哪些编程知识高明公司搜索seo
  • 郑州网站建设新闻电商网店
  • 青岛博海建设网站谷歌浏览器下载手机版
  • 垂直类网站怎么做推广广州seo关键词优化费用
  • 别人带做的网站关闭了权限咋办seo免费培训
  • 重庆网站目录关键词优化排名费用
  • 楼盘 东莞网站建设广告平台网站有哪些
  • 树莓派wordpress建站网站推广找客户
  • 用flash制作网站免费注册公司
  • 网站优化主要怎么做seo职位
  • 房地产的设计网站建设前端培训
  • 手机批发网北京网站优化怎么样
  • 深圳做微信网站建设优化设计答案六年级上册语文
  • 做网站商城需要什么软件制造企业网站建设
  • 做网站是怎么赚钱吗今天nba新闻最新消息
  • 淘宝网站建设的主要工作广告公司收费价格表
  • 做网站的实施过程seo黑帽是什么
  • asp在线生成网站地图源代码seo精灵
  • 百度seo刷排名软件百度seo排名360
  • wordpress扫码支付宝深圳百度推广优化
  • 网站建设外地便宜百度网盘app下载安装电脑版
  • 温州做网站定制源码交易平台
  • 做网站猫腻大吗seo推广薪资
  • 如何建一个简单的网站20条优化措施
  • 论坛网站开发的目的和意义厦门seo排名优化方式
  • 鞍山手机网站设计网店如何引流与推广
  • 网站开发专业就业前系军百度收录软件
  • 建设银行考试报名网站网络营销战略
  • 深圳建设工程网关键词优化报价推荐