# Questions tagged [fixed-point]

The tag has no usage guidance.

13 questions
Filter by
Sorted by
Tagged with
1 vote
621 views

### What does mulDivDown mean?

https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol This above is the link of FixedPointMathLib.sol. There are these functions .Can somebdoy explain what the function ...
45 views

### How to store values ​with decimal places? [duplicate]

I need to calculate values ​​for percentage and I need them to have two decimal places and the minimum value is 0.00 and the maximum value is 100.00. When I use some decimal place, for example: 80.01 ...
453 views

### Multiplying fixed-point types in Solidity

I would like to define a function like this: function convert(ufixed x) external pure returns (uint256 result) { result = x * 1e18; } Unfortunately, the code above does not compile: TypeError: ...
1 vote
287 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 ...
• 149
318 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) ...
• 1,633
817 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 ...
• 1,633
2k 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 ...
• 663
1k 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
149 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 ...
• 105
468 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
155 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 ...
• 643
1 vote
410 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. ...
• 11.2k