News for hackers. Stuff that matters.
Re:Copilot regurgitating Quake code, including sweary comments by ronnier on Friday July 02, 2021 @09:36AM (#27711329)
In its base unit. So cents in USD. Which can be an int64

Or if your language has something specific built in, use that.

Re:Copilot regurgitating Quake code, including sweary comments by ainar-g on Friday July 02, 2021 @09:40AM (#27711372)
> Or if your language has something specific built in, use that.

Unless your language is PostgreSQL's dialect of SQL, apparently. https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use...

Re:Copilot regurgitating Quake code, including sweary comments by pilif on Friday July 02, 2021 @10:16AM (#27711798)
It has the same issue that the other suggestion of your parent comment had: it can’t deal with fractions of cents, which is an issue you will most likely run into before you will into floating point rounding issues.
Re:Copilot regurgitating Quake code, including sweary comments by fredros on Friday July 02, 2021 @10:21AM (#27711873)
Of course for databases you should use a decimal.
Re:Copilot regurgitating Quake code, including sweary comments by tzs on Friday July 02, 2021 @12:19PM (#27713489)
> In its base unit. So cents in USD. Which can be an int64.

Note that if you use cents in the US so that everything is an integer then as long as you do not have to deal with amounts that are outside the range [-$180 trillion, $180 trillion] you can also use double. Double can exactly represent all integer numbers of cents in that range.

This may be faster than int64 on some systems, especially on systems that do not provide int64 either in hardware or in the language runtime so you'd have to do it yourself.

Re:Copilot regurgitating Quake code, including sweary comments by umanwizard on Friday July 02, 2021 @09:37AM (#27711350)
Not necessarily. It depends on the application.