tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
84.48k stars 2.54k forks source link

[bug] number covert 13.6 ==> 13.600000381469727 #10576

Closed lwp001 closed 2 months ago

lwp001 commented 2 months ago

Describe the bug

[derive(Debug, Serialize)]

pub struct DpfOrScr { pub utc: String, pub speed: f64, pub atmospheric_pressure: f64, pub torque: i16, pub friction_torque: i16, pub engine_speed: f64, pub fuel_flow: f64, pub scr_up_nox: f64, pub scr_down_nox: f64, pub reagent_surplus: f64, pub air_inflow: f64, pub scr_entrance_temperature: f64, pub scr_export_temperature: f64, pub dpf_diference_pressure: f64, pub coolant_temperature: i16, pub liquid_level: f32, pub egr: f64, pub egr_set: f64, }

[tauri::command]

fn greet(name: &str) -> DpfOrScr { // format!("Hello, {}! You've been greeted from Rust!", name) DpfOrScr { utc:"2024-08-01 11:00:39".to_string(), speed:5.09765625, atmospheric_pressure:97.0, torque:22, friction_torque:11, engine_speed:746.0, fuel_flow:4.3, scr_up_nox:0.0307675, scr_down_nox:0.030767500000000003, reagent_surplus:47.2, air_inflow:229.0, scr_entrance_temperature:85.3125, scr_export_temperature:1774.96875, dpf_diference_pressure:0.2, coolant_temperature:35, liquid_level:13.6,
egr:163.0, egr_set:163.8375 } }

front view

{ "air_inflow": 229, "atmospheric_pressure": 97, "coolant_temperature": 35, "dpf_diference_pressure": 0.2, "egr": 163, "egr_set": 163.8375, "engine_speed": 746, "friction_torque": 11, "fuel_flow": 4.3,

"liquid_level": 13.600000381469727,

"reagent_surplus": 47.2, "scr_down_nox": 0.030767500000000003, "scr_entrance_temperature": 85.3125, "scr_export_temperature": 1774.96875, "scr_up_nox": 0.0307675, "speed": 5.09765625, "torque": 22, "utc": "2024-08-01 11:00:39" }

Reproduction

No response

Expected behavior

13.6 ===>13.6

Full tauri info output

> test@0.0.0 tauri
> tauri info

[✔] Environment
    - OS: Windows 10.0.26257 X64
    ✔ WebView2: 126.0.2592.113
    ✔ MSVC: Visual Studio Enterprise 2022
    ✔ rustc: 1.82.0-nightly (730d5d409 2024-08-10)
    ✔ cargo: 1.82.0-nightly (0d8d22f83 2024-08-08)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: nightly-x86_64-pc-windows-msvc (default)
    - node: 22.5.1
    - pnpm: 9.7.0
    - npm: 10.8.2

[-] Packages
    - tauri [RUST]: 2.0.0-rc.2
    - tauri-build [RUST]: 2.0.0-rc.2
    - wry [RUST]: 0.41.0
    - tao [RUST]: 0.28.1
    - @tauri-apps/api [NPM]: 2.0.0-rc.0
    - @tauri-apps/cli [NPM]: 2.0.0-rc.3

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: Vue.js
    - bundler: Vite

Stack trace

No response

Additional context

No response

FabianLars commented 2 months ago

Welcome to the wonderful world of javascript (though tbf this problem applies to all languages). I'd recommend to change to rust side to either send the numbers as strings, or split them up into integers. Then on the js side, either use them as strings too, or try to convert them to BigInt.

Anyway, this is not a tauri specific problem so general resources you can find on this topic on the internet should apply here too.

lwp001 commented 2 months ago

thanks