sharkdp / insect

High precision scientific calculator with support for physical units
https://numbat.dev/
MIT License
3.17k stars 125 forks source link

Add optional precision argument to round() #379

Closed sadmoonphoenix closed 11 months ago

sadmoonphoenix commented 1 year ago

For example, round(x,y) x would be the number to round y would be how many digits to include

round(1.11111,1) would return "1" round(1.11111,2) would return "1.1" and so on....

sadmoonphoenix commented 1 year ago

(This would be pretty easy I figure, I'm just having trouble finding where this function is programmed)

triallax commented 1 year ago

What's the use case behind this? I could understand the need for this in an e.g. programming language, but how would it be helpful in Insect?

sadmoonphoenix commented 1 year ago

@mhmdanas being able to quickly round to numbers other than whole numbers would be useful for a variety of reasons, e.g. you're stupid like I am

sharkdp commented 1 year ago

I'm in favor of implementing this, but I'm currently not sure if we have support for functions like this (with optional or defaulted parameters). We definitely want to maintain the single-parameter version.

Also, let's make sure that the two-parameter version is close in behavior to existing two-parameter versions of round in e.g. Python.

triallax commented 1 year ago

I'm in favor of implementing this, but I'm currently not sure if we have support for functions like this (with optional or defaulted parameters). We definitely want to maintain the single-parameter version.

Yeah, we don't have anything like that at the moment, but I think it wouldn't be too difficult to implement.

Also, let's make sure that the two-parameter version is close in behavior to existing two-parameter versions of round in e.g. Python.

Agreed, researching what popular languages do by default is a good idea.

sharkdp commented 11 months ago

If someone still thinks this is valuable, please open a follow-up ticket in the https://github.com/sharkdp/numbat project.