Skip to content

Add a method to shift the decimal point #66

@rickb777

Description

@rickb777

Although it's possible to multiply by 10, 100, 1000 etc, or divide by powers of ten, it would be more efficient to have a method that does this by moving the decimal point.

I noticed that fint.lsh(int) does this, along with fint.rshUp(int) and its siblings. However, these are not visible, and maybe they're not practical either.

An example use-case is to parse a number such as "123MHz". Separating the string parts is easy, but then the number v, which is 123, has to be multiplied by v.MulExact(decimal.MustNew(1_000_000, 0), v.Scale()).

Another example is to parse a number such as "0.123µl". Separating the string parts is easy, but then the number v, which is 0.123, has to be multiplied by v.MulExact(decimal.MustNew(1, 6), v.Scale().

v.Shift(6) or v.Shift(-6) or some left/right shift methods would be simpler to understand I think.

https://go.dev/play/p/VlZCy_jrQch

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions