diff --git a/main.js b/main.js index 6fa3b48..e024e72 100644 --- a/main.js +++ b/main.js @@ -46,31 +46,33 @@ Vue.prototype.$validator = function (rule) { // cookie.clearAll(); // cookie.set(CACHE_KEY, 1); // } -//强制转为几位小数,不足的补0 -var forceToDecimal = function changeToDecimal(x, len, ignore = false) { - var f_x = parseFloat(x); +// 强制转为几位小数,不足的补0 +const forceToDecimal = function changeToDecimal(value, len = 1) { + const f_x = parseFloat(value) if (isNaN(f_x)) { - return 0; + return 0 } - var f = Math.round(f_x * 100) / 100; - if (ignore) { - f = Math.floor(f_x * 100) / 100; - } - var s = f.toString(); - var rs = s.indexOf('.'); + let s = f_x.toString() + let rs = s.indexOf('.') if (rs < 0) { - rs = s.length; - s += '.'; + rs = s.length + s += '.' } while (s.length <= rs + len) { - s += '0'; + s += '0' } - return s; + const tempArr = s.split('.') + const decimalArr = tempArr[1].split('') + let res = tempArr[0] + '.' + for (let i = 0; i < len; i++) { + res += decimalArr[i] + } + return res } -//强制转为2位小数,不足的补0 -var force2Decimal = function change2Decimal(x, ignore = false) { - return forceToDecimal(x, 2, false); +// 强制转为2位小数,不足的补0 +const force2Decimal = function change2Decimal(value) { + return forceToDecimal(value, 2) } Vue.prototype.$force2Decimal = force2Decimal diff --git a/pagesInn/inn/innHome.vue b/pagesInn/inn/innHome.vue index e2a988e..0be6575 100644 --- a/pagesInn/inn/innHome.vue +++ b/pagesInn/inn/innHome.vue @@ -757,8 +757,8 @@ export default { _this.isLike = data.zanVo !== null _this.isFavorite = data.hasFavorite _this.favoriteCount = data.favoriteCount - _this.inn.latitude = _this.inn.latitude ? parseFloat(_this.inn.latitude) : 24.993587 - _this.inn.longitude = _this.inn.longitude ? parseFloat(_this.inn.longitude) : 102.779656 + _this.inn.latitude = _this.inn.latitude > 0 ? _this.inn.latitude : 24.993587 + _this.inn.longitude = _this.inn.longitude > 0 ? _this.inn.longitude : 102.779656 // fix bug#1107 if (!_this.isLoad) { // 该店铺无商品则不显示“精选商品”