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
Is Netflix Free With Amazon Prime?
12 Reasons You’re Always Tired (and What to Do About It)
How To Start a Consignment Shop in 12 Steps (2024) - Shopify
Katie Nickolaou Leaving
Tabc On The Fly Final Exam Answers
CLI Book 3: Cisco Secure Firewall ASA VPN CLI Configuration Guide, 9.22 - General VPN Parameters [Cisco Secure Firewall ASA]
Overnight Cleaner Jobs
Moviesda Dubbed Tamil Movies
zopiclon | Apotheek.nl
Chicken Coop Havelock Nc
Industry Talk: Im Gespräch mit den Machern von Magicseaweed
Craigslist Mpls Cars And Trucks
Unlv Mid Semester Classes
Google Flights Missoula
De beste uitvaartdiensten die goede rituele diensten aanbieden voor de laatste rituelen
Craigslistjaxfl
Schedule 360 Albertsons
White Pages Corpus Christi
Music Go Round Music Store
The BEST Soft and Chewy Sugar Cookie Recipe
At&T Outage Today 2022 Map
Gas Buddy Prices Near Me Zip Code
Teekay Vop
Vernon Dursley To Harry Potter Nyt Crossword
Walgreens Bunce Rd
Apartments / Housing For Rent near Lake Placid, FL - craigslist
Kohls Lufkin Tx
Blackboard Login Pjc
Feathers
Shelby Star Jail Log
Santa Barbara Craigs List
Where to eat: the 50 best restaurants in Freiburg im Breisgau
950 Sqft 2 BHK Villa for sale in Devi Redhills Sirinium | Red Hills, Chennai | Property ID - 15334774
Helloid Worthington Login
Homewatch Caregivers Salary
Build-A-Team: Putting together the best Cathedral basketball team
Mta Bus Forums
Toonily The Carry
Natashas Bedroom - Slave Commands
Anya Banerjee Feet
Letter of Credit: What It Is, Examples, and How One Is Used
Sas Majors
22 Golden Rules for Fitness Beginners – Barnes Corner Fitness
Matt Brickman Wikipedia
Paperlessemployee/Dollartree
A rough Sunday for some of the NFL's best teams in 2023 led to the three biggest upsets: Analysis
Nearest Wintrust Bank
Every Type of Sentinel in the Marvel Universe
How to Do a Photoshoot in BitLife - Playbite
The Significance Of The Haitian Revolution Was That It Weegy
O'reilly's Eastman Georgia
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.