Comments (1)
I have no experience with avro but I read that it stores decimals using the two’s-complement representation of the unscaled integer value in big-endian byte order, so the following function should work.
It assumes that the decimals will be positive values. If not, then test the highest bit of the first byte and if it is set then invert all the bits by subtracting each byte from 256 before convertion to hex, then add one to the BigInt result.
// Must be greater or equal to 38 if you are decoding values with a precision of 38.
Decimal.precision = 40;
const bufferToDecimal = (buf, scale) => new Decimal(
BigInt(buf.reduce((hex, byte) => hex + byte.toString(16).
padStart(2, '0'), '0x')).toString()
).div(10 ** scale);
from decimal.js.
Related Issues (20)
- Return type of sign() is Decimal in d.ts HOT 3
- some cases normal operations still accurate than decimal.js HOT 4
- jest toEqual doesn't work HOT 1
- mathjs and decimal.js output different results HOT 1
- Allow creation without the `new` keyword HOT 4
- isPositive() should return false for zero HOT 1
- Maximum call stack size exceeded HOT 3
- Precision is lost when working with cyclic division HOT 1
- Round Half Up working as expected? HOT 1
- toFixed() is inconsistent in some way HOT 3
- Add structuredClone support HOT 3
- Deviding by 3 HOT 3
- Create a security policy HOT 1
- Assigning to constructor at runtime
- Support for mathematical expression processing without loss of precision HOT 2
- Decimal.sum with large arrays exceeds the maximum call stack size
- question:Value of type 'typeof Decimal' is not callable. Did you mean to include 'new'? HOT 2
- Suggestion: new method `toFixedNumber(...)` that returns a number HOT 6
- Irregular length of precision for at least .sub method HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from decimal.js.