question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong float values via `findCustomMessageOption`

See original GitHub issue

I ran into a float decoding issue with the output of findCustomMessageOption() when generating code for float validation rules as defined here:

https://github.com/bufbuild/protoc-gen-validate/blob/main/tests/harness/cases/numbers.proto#L8

The value 1.23 in that float.const option is turned into 1.2300000190734863 once it reaches my protoplugin code generator here.

As seen here (in the output): https://github.com/fubhy/protobuf-zod/blob/main/packages/protoc-gen-validate-zod/tests/harness/cases/numbers_zod.ts#L47-L51

Is that a known issue or am I doing sth. wrong or is there a bug with that? I can dig deeper myself if nothing comes to mind right away but I thought I’d ask first …

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
smaye81commented, Nov 2, 2022

Yeah meant to respond. After some investigation to verify we are parsing these correctly, this actually is expected just by the nature of precision with floating-point in JavaScript. There’s really not much we can do to alleviate it, since it’s part of the language itself.

0reactions
fubhycommented, Nov 2, 2022

I guess it boils down to this …

const view = new DataView(new ArrayBuffer(16));
view.setFloat32(0, 1.23, true);
view.getFloat32(0, true); // 1.2300000190734863

Which, I guess, is expected.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to handle floats and decimal separators with html5 input ...
I haven't been able to find a way to turn HTML5 validation off. I can turn off or customize the error message, but...
Read more >
float | CSS-Tricks
The float property in CSS is used for positioning and layout on web pages. A common usage might be floating an image to...
Read more >
float - CSS: Cascading Style Sheets - MDN Web Docs - Mozilla
The float CSS property places an element on the left or right side of its container, allowing text and inline elements to wrap...
Read more >
You cannot convert text to number when the cell contains a ...
In the Rules section, make sure the Number stored as text rule is selected, and then click OK. To do this in Microsoft...
Read more >
Language Guide | Protocol Buffers - Google Developers
As you can see, each field in the message definition has a unique number. These numbers are used to identify your fields in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found