zoukankan      html  css  js  c++  java
  • 处理地图经纬度,保留6位小数

    过滤String 、Boolean 、Undefined、Null 类型,将用户输入值返回处理成Number类型且保留6位

     1      /*
     2          * 处理经纬度数据 小数点保留六位
     3          * 经度范围 -180 ~ 180
     4          * 纬度范围 -90 ~ 90
     5          * 超出方位 返回0度
     6          *
     7          */
     8         function longLatitude(longLatVal, isLongitude) {
     9             //处理NaN类型
    10             const longlat = parseFloat(longLatVal);       
    11             if (isNaN(longlat)) {        
    12                 return 0;       
    13             }
    14 
    15             // 经度范围 -180 ~ 180 ;纬度范围 -90 ~ 90
    16             const range = isLongitude ? 180 : 90;
    17             if (Math.abs(longlat) > range) {
    18                 return 0
    19             }
    20             
    21             //小数点保留六位
    22             if (longlat.toString().indexOf('.') > 0) {        
    23                 const longlatsplit = longLatVal.toString().split('.');       
    24                 if (longlatsplit.length >= 2) {          
    25                     return parseFloat(longlatsplit[0] === "" ? 0 : longlatsplit[0]) + parseFloat("." + longlatsplit[1].slice(0, 6));        
    26                 }      
    27             }
    28   
    29             return longlat;
    30         }
    31         // 下列以经度测试输出值
    32         longLatitude(-10, true)               //0
    33         longLatitude('非number', true)         //0
    34         longLatitude('0.001', true)         //0.001
    35         longLatitude('001.001', true)          //1.001
    36         longLatitude('001.001.0001', true)     //1.001
    37         longLatitude('001.001000000.0001', true)   //1.001

      

    游走大神世界,体验代码魅力
  • 相关阅读:
    jmeter非GUI模式命令
    jmeter性能测试--浪涌测试
    性能测试之场景设计
    性能测试用例实例
    jmeter常见错误及解决方法
    .NET中变量生存期
    SQL数据库从高版本导入低版本
    对称子字符串
    回溯法求解全排列问题(可去除重复排列)
    快速排序及快速选择问题
  • 原文地址:https://www.cnblogs.com/hongding/p/11008464.html
Copyright © 2011-2022 走看看