Decimal precision for API calculations (2024)

Decimal precision for API calculations

Calculated versus displayed precision

Internal API calculations are performed using as many decimal places as necessary depending upon the precision of the currency in question, but displayed values are sometimes rounded/truncated to achieve a usable value or for formatting purposes.

For example, Bitcoin (BTC) calculations use up to 10 decimal places (the maximum usable precision for BTC is 8 places), but are sometimes displayed using only 5 decimal places. Similarly, US Dollar (USD) calculations use up to 4 decimal places (the maximum usable precision for USD is of course 2 places), but are often displayed using only 2 decimal places.

The REST API Assets endpoint can be used to determine the maximum decimal precisions for individual currencies:

$ ./krakenapi Assets asset=xbt,usd{"error":[],"result":{"XXBT":{"aclass":"currency","altname":"XBT","decimals":10,"display_decimals":5},"ZUSD":{"aclass":"currency","altname":"USD","decimals":4,"display_decimals":2}}}

As shown, the Assets endpoint provides the calculation decimal precisions via the decimals fields, and provides the display decimal precisions via the display_decimals fields.

Matching local values with API values

Values derived from local calculations (such as calculating balance changes from a trade's price and volume) often have more decimal places than required, and need to be rounded/truncated to match the values provided by the API.

For example, a SHIB/USD order to buy 50,123 SHIB at $0.00002901 results in a trade worth $1.45406823 (50,123 x 0.00002901 = 1.45406823), but the REST API Ledgers endpoint shows that the USD balance decreased by a smaller precision value of $1.4541:

"L2A7BN-OLRUR-DGZH7F":{"refid":"T5JORM-HM432-GQ3RGY","time":1639991413.4671,"type":"trade","subtype":"","aclass":"currency","asset":"ZUSD","amount":"-1.4541","fee":"0.0000","balance":"124.7277"}

The solution to this type of decimal precision discrepancy is to round/truncate local values to match the decimal precision provided by the REST API Assets endpoint.

Continuing the SHIB/USD example, the Assets endpoint indicates a USD calculation precision of 4 (see the previous section above), hence the locally calculated value of $1.45406823 should also be rounded/truncated to a decimal precision of 4:

  • 50,123 x 0.00002901 = 1.45406823 rounded to 4 places = 1.4541

As shown, by rounding/truncating to the appropriate decimal precision, the final value of $1.4541 corresponds exactly to the value provided by the Ledgers endpoint, allowing local values to be matched with API values successfully.

Decimal precision for API calculations (2024)

FAQs

Decimal precision for API calculations? ›

Internal API calculations are performed using as many decimal places as necessary depending upon the precision of the currency in question, but displayed values are sometimes rounded/truncated to achieve a usable value or for formatting purposes.

What is the decimal point of precision? ›

Precision is the number of digits in a number. Scale is the number of digits to the right of the decimal point in a number. For example, the number 123.45 has a precision of 5 and a scale of 2 .

How to calculate decimal precision? ›

The rule states that you can simply count the number of decimals in two numbers and their product will have the precision of the sum of the decimals of those two numbers. In usual usage, 0.01 and 0.002 each have one digit of precision. The leading zeros just position the decimal point.

What is the best decimal precision for money? ›

Decimal / Numeric

Assume your application must handle money values up to a trillion dollars. In that case, the following should work: 13,2 and If you must adhere to GAAP (Generally Accepted Accounting Principles), use 4 for precision, such as 13,4.

How many decimal places do measurements need? ›

It is common to report up to two significant figures and a maximum of three decimal places, such as p = 0.12, p = 0.035, p = 0.006 and p < 0.001. Some examples of suitable and less suitable numbers of decimal places are shown in Figure 1.

Has 7 decimal digits of precision? ›

A single-precision float only has about 7 decimal digits of precision (actually the log base 10 of 223, or about 6.92 digits of precision).

What does 3 decimals of precision mean? ›

Rounding to three decimal places (i.e. up to thousandth place in decimal) means that the number should not have any digit from fourth place onwards.

How to do precision calculations? ›

To calculate precision using a range of values, start by sorting the data in numerical order so you can determine the highest and lowest measured values. Next, subtract the lowest measured value from the highest measured value, then report that answer as the precision.

What is 4 digit decimal precision? ›

To have four decimal places is to have four (or fewer) digits to the right of the decimal point when written in decimal notation e.g. 12.3456. Typically we would pad a number with fewer than four digits, so 1.23 would be written 1.2300 in scientific work to indicate its precision level.

What is 6 decimal digit precision? ›

For example, a "precision of six decimal digits" or "six-digit precision" means that the type's binary representation is precise enough to store a real number of six decimal digits, so that its conversion back into a six-digit decimal number yields the original six digits.

Is 10% precision good? ›

For a good measurement system, the accuracy error should be within 5% and precision error should within 10%.

What is the highest precision of a decimal? ›

The most precise fractional value (between 0 and 1, or 0 and -1) is represented by DECIMAL(38, 38) , with 38 digits to the right of the decimal point. The value closest to 0 would be . 0000...1 (37 zeros and the final 1).

How many decimal places should your financial calculation show? ›

It is standard for most currencies to display two decimal places (i.e. $74.62).

How many decimal places to use in calculation? ›

Experienced researchers typically round the numbers to one or two decimals, following the APA manual.

What is the decimal places of precision? ›

Price precision determines the fixed number of decimal places to which a calculated price is rounded. Suppose precision is set at 2 digits. If the value of the third digit to the right of the decimal is less than 5, the hundredth position (second to the right of the decimal) remains unchanged.

What is the difference between decimal and precision? ›

DECIMAL provides an exact numeric in which the precision and scale can be arbitrarily sized. You can specify the precision (the total number of digits, both to the left and the right of the decimal point) and the scale (the number of digits of the fractional component).

What is the precision of decimal degrees? ›

Precision. A value in decimal degrees to a precision of 4 decimal places is precise to 11.1 metres (36 ft) at the equator. A value in decimal degrees to 5 decimal places is precise to 1.11 metres (3 ft 8 in) at the equator.

What does 6 decimal digits precision mean? ›

For example, a "precision of six decimal digits" or "six-digit precision" means that the type's binary representation is precise enough to store a real number of six decimal digits, so that its conversion back into a six-digit decimal number yields the original six digits.

What is the precision of 4 decimal places? ›

To have four decimal places is to have four (or fewer) digits to the right of the decimal point when written in decimal notation e.g. 12.3456. Typically we would pad a number with fewer than four digits, so 1.23 would be written 1.2300 in scientific work to indicate its precision level.

What is the precision of currency decimals? ›

Understanding Currency Precision

According to the ISO standard, currency precision can range from zero decimals to three decimals. For example, USD amounts have two digits to the right of the decimal, and JPY have none.

Top Articles
Swap Definition & How to Calculate Gains
Ubuntu: How much drive space does it need?
Woodward Avenue (M-1) - Automotive Heritage Trail - National Scenic Byway Foundation
Pet For Sale Craigslist
Asian Feels Login
How Many Cc's Is A 96 Cubic Inch Engine
Chris wragge hi-res stock photography and images - Alamy
San Diego Terminal 2 Parking Promo Code
35105N Sap 5 50 W Nit
Lycoming County Docket Sheets
Craigslist Estate Sales Tucson
Jessica Renee Johnson Update 2023
Sitcoms Online Message Board
Brenna Percy Reddit
Our Facility
Inevitable Claymore Wow
House Party 2023 Showtimes Near Marcus North Shore Cinema
Bend Pets Craigslist
Nail Salon Goodman Plaza
Craigslist Missoula Atv
10 Fun Things to Do in Elk Grove, CA | Explore Elk Grove
/Www.usps.com/International/Passports.htm
Uta Kinesiology Advising
Homeaccess.stopandshop
Sullivan County Image Mate
Panolian Batesville Ms Obituaries 2022
yuba-sutter apartments / housing for rent - craigslist
Gas Buddy Prices Near Me Zip Code
Kroger Feed Login
Skepticalpickle Leak
Willys Pickup For Sale Craigslist
Club Keno Drawings
1475 Akron Way Forney Tx 75126
The Rise of "t33n leaks": Understanding the Impact and Implications - The Digital Weekly
Smayperu
The Menu Showtimes Near Amc Classic Pekin 14
Verizon TV and Internet Packages
Beaver Saddle Ark
2012 Street Glide Blue Book Value
How to Play the G Chord on Guitar: A Comprehensive Guide - Breakthrough Guitar | Online Guitar Lessons
Rocketpult Infinite Fuel
Craigslist Car For Sale By Owner
Sephora Planet Hollywood
Toth Boer Goats
Td Ameritrade Learning Center
Bernie Platt, former Cherry Hill mayor and funeral home magnate, has died at 90
Lucyave Boutique Reviews
Petra Gorski Obituary (2024)
CrossFit 101
The Complete Uber Eats Delivery Driver Guide:
Euro area international trade in goods surplus €21.2 bn
Product Test Drive: Garnier BB Cream vs. Garnier BB Cream For Combo/Oily Skin
Latest Posts
Article information

Author: Msgr. Benton Quitzon

Last Updated:

Views: 6528

Rating: 4.2 / 5 (63 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Msgr. Benton Quitzon

Birthday: 2001-08-13

Address: 96487 Kris Cliff, Teresiafurt, WI 95201

Phone: +9418513585781

Job: Senior Designer

Hobby: Calligraphy, Rowing, Vacation, Geocaching, Web surfing, Electronics, Electronics

Introduction: My name is Msgr. Benton Quitzon, I am a comfortable, charming, thankful, happy, adventurous, handsome, precious person who loves writing and wants to share my knowledge and understanding with you.