Skip to content
Advertisement

Calculating the maximum value for a decimal using scale and precision

I am working on a JavaScript function that takes two values: precision of a decimal value & scale of a decimal value.

This function should calculate the maximum value that can be stored in a decimal of that size.

For example: a decimal with a precision of 5 and a scale of 3 would have a maximum value of 99.999.

What I have does the job, but it’s not elegant. Can anyone think of something more clever?

Also, please forgive the use of this weird version of Hungarian notation.

JavaScript

Advertisement

Answer

Haven’t tested it:

JavaScript

precision must be positive

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement