From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 5D3211FF13B for ; Wed, 06 May 2026 23:19:51 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 334074704; Wed, 6 May 2026 23:19:51 +0200 (CEST) Message-ID: <64564f66-5688-41b8-897b-7481ceb2c74e@proxmox.com> Date: Wed, 6 May 2026 23:19:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Subject: Re: [PATCH yew-widget-toolkit v3] widget: form: number: round floats to some decimal precision To: Christoph Heiss , yew-devel@lists.proxmox.com References: <20260505132650.1158715-1-c.heiss@proxmox.com> Content-Language: en-US From: Thomas Lamprecht In-Reply-To: <20260505132650.1158715-1-c.heiss@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1778102276631 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.003 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [rust-lang.org] Message-ID-Hash: HGFYZSAF7OC4V3SVVKZF7MJLV6VGQBN6 X-Message-ID-Hash: HGFYZSAF7OC4V3SVVKZF7MJLV6VGQBN6 X-MailFrom: t.lamprecht@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Yew framework devel list at Proxmox List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Am 05.05.26 um 15:25 schrieb Christoph Heiss: > The decimal precision is controllable through a property. > > E.g. previously, for an input like > > Number::new() > .name("some-float") > .step(0.1) > .value(0.2) > > and pressing the "range-up" button on the input would result in > 0.30000000000000004 - which is rather undesirable. > > Rounding is done on step up, step down, on creation, on the validated > form value and on the parsed value for `on_input`, if any. While this should address such rounding on stepping, a user entering 0.30000000000000004 explicitly and then submitting that would still result in the not-rounded value getting submitted. What about just rounding in the validator, which is basically the single source of truth and might also make this change a bit shorter. I.e., add decimal_places to the ValidateClosure generic struct. Am 05.05.26 um 15:25 schrieb Christoph Heiss: > @@ -79,6 +81,12 @@ impl NumberTypeInfo for f64 { > fn is_decimal() -> bool { > true > } > + fn round_to_precision(&self, precision: u8) -> Self { > + // Do a little dance here to round to the nearest step value, by multiplying, > + // rounding to the nearest integer and dividing again > + let m = 10f64.powf(precision as f64); As precision is always an integer this should probably use [powi] over powf, which should be also slightly faster, not that it matters much here. [powi]: https://doc.rust-lang.org/std/primitive.f64.html#method.powi > + (self * m).round() / m > + } > } > > // Note: Error message from rust parse() are not gettext translated, so try to do all