update: 解决浮点数问题

This commit is contained in:
admin 2024-07-22 10:10:35 +08:00
parent 28c42f400e
commit 12f325e46e
3 changed files with 71 additions and 11 deletions

View File

@ -43,13 +43,13 @@
{{ {{
model1.order.buttonType === 0 model1.order.buttonType === 0
? isKg() ? isKg()
? item.unit ? item.settlementUnit
: item.unit1 || item.unit : item.unit1 || item.unit
: "%" : "%"
}} }}
</text> </text>
<text v-else> <text v-else>
{{ isKg() ? item.unit : item.unit1 || item.unit }} {{ isKg() ? item.settlementUnit : item.unit1 || item.unit }}
</text> </text>
</template> </template>
</u-input> </u-input>
@ -105,7 +105,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { PictureApi, ShipmentApi } from "@/services"; import { PictureApi, ShipmentApi } from "@/services";
import type { ComType } from "@/types/global"; import type { ComType } from "@/types/global";
import { formatDate } from "@/utils"; import { formatDate, num_subtract } from "@/utils";
import { import {
ImagesType, ImagesType,
OrderType, OrderType,
@ -190,11 +190,11 @@ const model1 = reactive<{
subtractNum: 0, subtractNum: 0,
grossWeight: 0, // grossWeight: 0, //
tare: 0, // tare: 0, //
unit: 1, settlementUnit: 1,
}, },
}); });
const isKg = () => { const isKg = () => {
if (model1.order.unit === 1) { if (model1.order.settlementUnit === 1) {
return false; return false;
} else { } else {
return true; return true;
@ -272,7 +272,7 @@ const contrlModalParams = reactive<ComType>({
const formAttrList = reactive<ComType>([ const formAttrList = reactive<ComType>([
{ {
name: "称重单位", name: "称重单位",
key: "unit", key: "settlementUnit",
type: "radio", type: "radio",
child: [ child: [
{ {
@ -471,8 +471,7 @@ watch(
预估总价 结算单价*结算重量 预估总价 结算单价*结算重量
实际收入实际结算金额-运费-杂费 实际收入实际结算金额-运费-杂费
*/ */
model1.order.settlementNet = model1.order.settlementNet = num_subtract((settlementGrossNew || 0), (settlementTareNew || 0))
(settlementGrossNew || 0) - (settlementTareNew || 0);
if (model1.order.buttonType === 0) { if (model1.order.buttonType === 0) {
if (model1.order.subtractNum) { if (model1.order.subtractNum) {
model1.order.settlementWeight = model1.order.settlementWeight =
@ -705,7 +704,7 @@ onLoad((option) => {
fileLists: model1.order.fileLists.map((item: any) => { fileLists: model1.order.fileLists.map((item: any) => {
return { ...item, fileID: item.id }; return { ...item, fileID: item.id };
}), }),
unit: 1, settlementUnit: 1,
}; };
} }
}); });
@ -743,7 +742,7 @@ onLoad((option) => {
box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0, 56, 93, 0.12); box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0, 56, 93, 0.12);
border-radius: 13rpx 13rpx 0rpx 0rpx; border-radius: 13rpx 13rpx 0rpx 0rpx;
padding: 25rpx 50rpx; padding: 25rpx 50rpx;
position: fixed; position: sticky;
width: calc(100vw - 100rpx); width: calc(100vw - 100rpx);
bottom: 0rpx; bottom: 0rpx;
z-index: 999; z-index: 999;

View File

@ -54,7 +54,7 @@
state.scaleStatusBtnType === ScaleStatusBtnType.ShipmentNoPay state.scaleStatusBtnType === ScaleStatusBtnType.ShipmentNoPay
" "
> >
<text>审核人{{ state.order.pricingUserName || "-" }}</text> <text>审核人{{ state.order.updateName || "-" }}</text>
<text>过磅时间{{ state.order.tareTime }}</text> <text>过磅时间{{ state.order.tareTime }}</text>
</view> </view>

View File

@ -322,3 +322,64 @@ export function formatStartAndEndTime(str:string, type:string) {
} }
} }
// 两个浮点数求和
export function num_add(num1: number,num2: number){
var r1,r2,m;
try{
r1 = num1.toString().split('.')[1].length;
}catch(e){
r1 = 0;
}
try{
r2=num2.toString().split(".")[1].length;
}catch(e){
r2=0;
}
m=Math.pow(10,Math.max(r1,r2));
return Math.round(num1*m+num2*m)/m;
}
// 两个浮点数相减
export function num_subtract(num1: number,num2: number){
var r1,r2,m,n;
try{
r1 = num1.toString().split('.')[1].length;
}catch(e){
r1 = 0;
}
try{
r2=num2.toString().split(".")[1].length;
}catch(e){
r2=0;
}
m=Math.pow(10,Math.max(r1,r2));
n=(r1>=r2)?r1:r2;
return Number((Math.round(num1*m-num2*m)/m).toFixed(n));
}
// 两个浮点数相乘
export function num_multiply(num1: number,num2: number){
var m=0,s1=num1.toString(),s2=num2.toString();
try{m+=s1.split(".")[1].length}catch(e){};
try{m+=s2.split(".")[1].length}catch(e){};
return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m);
}
// 两个浮点数相除
export function num_divide(num1: number,num2: number){
var t1,t2,r1,r2;
try{
t1 = num1.toString().split('.')[1].length;
}catch(e){
t1 = 0;
}
try{
t2=num2.toString().split(".")[1].length;
}catch(e){
t2=0;
}
r1=Number(num1.toString().replace(".",""));
r2=Number(num2.toString().replace(".",""));
return (r1/r2)*Math.pow(10,t2-t1);
}