Questions tagged [fixed-point]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer

What does mulDivDown mean? This above is the link of FixedPointMathLib.sol. There are these functions .Can somebdoy explain what the function ...
Prajan Bhattarai's user avatar
0 votes
2 answers

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 ...
THIAGO DE BONIS's user avatar
2 votes
1 answer

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: ...
Paul Razvan Berg's user avatar
1 vote
1 answer

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 ...
0xOsiris's user avatar
  • 149
2 votes
0 answers

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) ...
MShakeG's user avatar
  • 1,633
2 votes
1 answer

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 ...
MShakeG's user avatar
  • 1,633
5 votes
1 answer

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 ...
Maxareo's user avatar
  • 663
3 votes
3 answers

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 ...
Brad's user avatar
  • 131
0 votes
1 answer

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 ...
kirgol's user avatar
  • 105
0 votes
1 answer

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%...
rosendin's user avatar
  • 107
0 votes
0 answers

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 ...
GN.'s user avatar
  • 643
1 vote
1 answer

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. ...
Patrick Collins's user avatar
26 votes
4 answers

Can't do any integer division

I'm building a new smart contract but really can't figure out how to perform integer division. I know that fixed point numbers haven't been implemented yet but it should be possible to perform 100/3 = ...
Hugo Moreau's user avatar