golang-nuts
Subject: Re: [go-nuts] Rounding to k digits
This message was sent by an external party.
The only thing a binary computer can store is a bit. A bit is either 0 or 1,
both are integers. Or we can say that it can only store booleans true and
false, but that doesn't chan
native” you mean “implemented by assembly instructions”, but
> then, floating point are implemented by assembly instructions…)
>
>
>
> Thomas
>
>
>
>
>
> *From:* 'Brian Candler' via golang-nuts
> *Sent:* Thursday, August 14, 2025 10:04 PM
> *To:* golang-nu
then,
floating point are implemented by assembly instructions…)
Thomas
From: 'Brian Candler' via golang-nuts
Sent: Thursday, August 14, 2025 10:04 PM
To: golang-nuts
Subject: Re: [go-nuts] Rounding to k digits
This message was sent by an external party.
On Wednesday, 13 August 2025 a
On Wednesday, 13 August 2025 at 20:10:50 UTC+7 Peter Weinberger (温博格) wrote:
The canonical reference on this is by Guy Steele, "How to Print
Floating Point Numbers Accurately"
See also:
https://0.30004.com/
--
You received this message because you are subscribed to the Google Grou
I'll add that I typically just use fmt.Sprintf("%v", x), which gives the
shortest possible unambiguous
string representation of the floating point value x.
On Wednesday, August 13, 2025 at 11:33:40 PM UTC+1 Jason E. Aten wrote:
> Hi Jochen,
>
> I think you can get what you want simply with the
Hi Jochen,
I think you can get what you want simply with the fmt package.
Consider fmt.Sprintf("%0.5f", x), for example, if you wanted 5 decimal
places.
If you need to actually round a floating point number, rather than just
displaying
a certain number of places, the CockroachDB guys wrote a
A floating point number cannot represent all possible real numbers - so when
you “shift it back” the number you expect may not be possible.
See this on why 0.1 cannot be represented.
https://how.dev/answers/why-does-01-not-exist-in-floating-point
> On Aug 13, 2025, at 7:55 AM, Jochen Voss wrot
ected from the properties of real numbers.
>
> Thomas
>
> -Original Message-
> From: 'Peter Weinberger (温博格)' via golang-nuts
>
> Sent: Wednesday, August 13, 2025 2:09 PM
> To: Alexander Ertli
> Cc: robert engels ; Jochen Voss ;
> golang-nuts
> Subj
Dear Peter,
Thanks for the reference!
All the best,
Jochen
On Wednesday, 13 August 2025 at 14:10:50 UTC+1 Peter Weinberger (温博格) wrote:
> The canonical reference on this is by Guy Steele, "How to Print
> Floating Point Numbers Accurately"
>
> On Wed, Aug 13, 2025 at 9:07 AM 'Alexander Ertli' vi
Hi Alexander,
Thanks, this is interesting. My original
func Round(x float64, digits int) float64 {
eps := math.Pow10(-digits)
return math.Round(x/eps) * eps
}
leads to near-immediate fuzzing failures, whereas your
func Round(x float64, digits int) float64 {
scale := math.Pow(10, float64(dig
c: robert engels ; Jochen Voss ;
golang-nuts
Subject: Re: [go-nuts] Rounding to k digits
This message was sent by an external party.
The canonical reference on this is by Guy Steele, "How to Print Floating Point
Numbers Accurately"
On Wed, Aug 13, 2025 at 9:07 AM 'Alexander Ertli
The canonical reference on this is by Guy Steele, "How to Print
Floating Point Numbers Accurately"
On Wed, Aug 13, 2025 at 9:07 AM 'Alexander Ertli' via golang-nuts
wrote:
>
> Hi Jochen,
>
> I think it's possible with a trick.
>
> My first naive thought on how to solve this is to simply shift the
Hi Jochen,
I think it's possible with a trick.
My first naive thought on how to solve this is to simply shift the decimal
point over, do the rounding on the whole number, and then shift it back.
import "math"
// Round performs rounding by shifting the decimal, rounding, and shifting
back.
func Ro
Dear Robert,
Thank you for your response. To make sure I understand: Are you saying
Claude's Round() function does not work? (For which example?) Or are you
saying it is impossible to do better than Claude's function?
Many thanks,
Jochen
On Wednesday, 13 August 2025 at 13:52:08 UTC+1 robert
Read up on numerical analysis - what you are asking for is impossible :)
You need to convert to a string, or use BCD/fixed place values - like
github.com/robaho/fixed
> On Aug 13, 2025, at 7:42 AM, Jochen Voss wrote:
>
> Dear all,
>
> I would like to define a function "func Round(x float64, d
15 matches
Mail list logo