Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

# Questions tagged [fixed-point]

The tag has no usage guidance.

12 questions
Filter by
Sorted by
Tagged with
1 vote
38 views

### Solidity 128.128 unsigned fixed point division

I am currently trying to figure out a concrete way to perform fixed point division on two 128.128 uint256 numbers. This seems like a fairly straightforward thing, but haven't been able to code a ...
38 views

### Handling fractions and fixed point number division

A contract im trying to implement distributes rewards to depositors, lets say totalDepositsWei = 2e18 totalRewardWei = 1e18 In my contract i'm effectively keeping track of reward per deposit which ...
25 views

### How to deal with funds lost to rounding errors in DeFi protocols?

What are the different methods that DeFi protocols use to handle rounding errors? For example say I have an ICO contract that returns 1/1e10 of the ICO token per ETH, so if you deposit 1 ETH(1e18 wei) ...
• 180
118 views

### How to floor or ceil a fixed point number?

Say I have a signed 64.64 fixed point number 18444899399302180000 or 0.9999 in floating point notation. How can I define a floor and ceil function that floors or ceils an int128 signed 64.64 fixed ...
• 180
768 views

### What does `decode112with18` do?

In a Solidity fixed point library, the function decode112with18 converts a uq112x112 to a uint value and I'm wondering what exactly is happening in the function. Thanks. // decode a uq112x112 into ...
• 429
506 views

### Converting Uniswap sqrtPriceX96 into wei

I'm trying to figure out how to convert a uniswap ratio into wei (and eventually ether). The uniswap docs commonly mention sqrtPriceX96: A Fixed point Q64.96 number representing the sqrt of the ratio ...
• 131
73 views

### How in Solidity can you get initial value from the sum of ratios to it?

In Solidity division of uint256 rounds down the value. Let's say I want to issue some token amount based on duration like this: uint256 MAX_TIME = 365 days; uint256 Duration1 = 223 days; uint256 ...
• 103
215 views

### DeclarationError: Identifier already declared even with inline function call

I got error in my smart contract, Pool.sol:10:1: DeclarationError: Identifier already declared. import './ERC20.sol'; ^------------------^ Token.sol:10:1: The previous declaration is here: contract ...
• 1
83 views

### Rounding fixed point integers

If I'm using fixed-point arithmetic to represent rates, for example, 2% in ray (27 decimal precision) would be 102000000000000000000000000000. If I had a rate like 101333333333333333333333333333 (1.33%...
• 107
76 views

### Can't store the value of a math operation. It's always 0

contract MyContract { uint public priceUSD = 1.70 * 10**8; // USD uint public priceEth; ......... function setPrice(uint newPriceUSD) external ownerOnly() returns(uint, uint) { uint ...
• 553
1 vote
220 views

### Why don't decimals work in solidity?

I've read this question and answer thread about representing decimal values in solidity, and I understand that math is entirely done using fixed-point. However, I'm curious as to why this is the case. ...
• 4,998