Questions tagged [decimals]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
16 views

How do I remove decimals from a uint256

I am calculating a buyPrice that has a factor of 1.2 times the normal price. To do this I get the token price and multiply it by 1200000000000000000 (18). It looks something like: uint256 buyPrice = ...
user avatar
0 votes
0 answers
25 views

How does decimal precision affect a Token in an exchange?

Suppose there is a token with a very small rate compared to USD (e.g. 0.00000001 USD). What are the disadvantages and advantages of adding more decimal places for that in an exchange? Does it make ...
user avatar
  • 1
0 votes
1 answer
16 views

Is there a list of all Ethereum unit converters?

I'm interested in converting Ether units to wei, plus other custom token amounts where the decimals may be different to 18. Is there a list of all Ethereum unit converters?
user avatar
0 votes
0 answers
75 views

Converting float token value to int

I would like to set the amountOutMin argument's value in the swapExactTokensForETH function of Uniswap V2. The value of the token I would like to receive back is 0.02 BNB. Which is a float while the ...
user avatar
  • 196
0 votes
0 answers
36 views

Why is decimals() required to return 18 in ERC777?

I was digging into the ERC777 standard, but reading the EIP I noticed that it states that for backward-compatibility purposes decimals() should always return 18. Why is this the case? AFAIK in ERC20 ...
user avatar
  • 103
0 votes
1 answer
33 views

Best Practice to handle big number

i have erc20 token with 18 decimal, the problem is if i want to transfer 100k token, the javascript can't handle that, because there will lot of 0. so in smart contract i override all the transfer ...
user avatar
0 votes
0 answers
17 views

how to store and use a fractionnal number for arithmetic operations in solidity? [duplicate]

I am trying to write a presale contract as an exercise that would allow the deployer to collect ether from buyers, then redistribute the amount of tokens proportionately to the amount spent by the ...
user avatar
0 votes
1 answer
70 views

How to converted a string into four numbers in smart contract?

I want to have a string that can be converted into four numbers. For example, it converts a string from E17B1237 into (225, 123, 18, 55), this is converted from hexadecimal into decimal. E1 => 225, ...
user avatar
  • 147
1 vote
1 answer
697 views

Can an ERC-20 have more than 18 decimals?

I've seen most tokens use 18 decimals and USDC use 6 decimals. Is it possible for a token to have over 18?
user avatar
  • 35
1 vote
1 answer
101 views

How to calculate $10 of ETH without arithmetic overflow

I'm using Chainlink's pricefeed to get the latest ETHUSD price. The value returned is 10**8, i.e. if the price of ETHUSD is 3981.43 then the value will be 398143000000. How can I calculate the WEI ...
user avatar
  • 117
0 votes
0 answers
20 views

Are there any popular ERC20 tokens that don't implement decimals() function?

decimals() function is not mandatory in IERC20. Are there any popular tokens that don't implement decimals()?
user avatar
0 votes
1 answer
478 views

Transaction failing due to can't estimate Gas Cost on Polygon

I have a function function tokenValue( address _token, uint _amount ) public view returns ( uint ) { return _amount.mul( 10 ** IERC20( MY_TOKEN ).decimals() ).div( 10 ** IERC20( _token )....
user avatar
1 vote
0 answers
293 views

How convert hex number to decimal in solidity?

I would like to convert a hex number to decimal.
user avatar
0 votes
2 answers
2k views

Decimal in Solidity [duplicate]

I'm new to solidity but I program in other languages, solidity looks a bit like javascript but recently I noticed a problem with solidity. it doesn't accept decimals and float numbers, like "0....
user avatar
  • 101
0 votes
0 answers
444 views

How to choose number of decimal places for token

What should I consider when choosing the number of decimal places for an ERC20 token/stablecoin? My first thought was to just use 18 which seems to be the standard because Ether uses 18. However ...
user avatar
1 vote
1 answer
45 views

ERC-20 interface decimal issue

i have created erc20 token with 100000 supply and decimal with 0. i wonder that if i ask an exchange to list my token. Are these decimal is problem? regards
user avatar
1 vote
1 answer
498 views

I'm confused about decimals and total Supply with my erc20 token

I created erc20 token. I want total supply of 50,00,000. And I want to give 7% tax on every transaction. So if anyone sends single coin then, how can I get 7% and transfer remaining to receiver? For ...
user avatar
3 votes
2 answers
896 views

price conversion using chainlink ETHUSD price

I'm storing a product's USD value in contract. mapping (string => uint256) productUSD; For example, if it's $52 I'd store it as productUSD[_product] = 52; Now, when people paying in ETH, I want to ...
user avatar
2 votes
2 answers
1k views

How can I multiply a fixed decimal var by a uint in solidity?

In base to this example: Dealing with multiplying fractions in solidity I am adding th DSMath correctly. I can operate and compile with integers but if I try to compile a contract with any decimal ...
user avatar
  • 558
1 vote
0 answers
699 views

Division and floor rounding with 18 decimals

I am recreating a UNISWAP-like AMM and have encountered problems anytime I want to divide the balances of tokens in my pool. For example: I want to require() that tokens are deposited in the correct ...
user avatar
0 votes
1 answer
112 views

I want to store decimal value in a storage variable and later use that variable at same precision in the formula later internally

I want to store uint public MINTING_VELOCITY = 0.000002; And later use it in the formula: A x t x MINTING_VELOCITY ,where A = 2000 ,t(staking_duration_time) = 120 Issue is currently MINTING_VELOCITY ...
user avatar
1 vote
1 answer
477 views

Vyper binary fixed point vs Decimal fixed point

there is something i do not understand in Vyper documentation: https://vyper.readthedocs.io/en/stable/index.html Binary fixed point: Decimal fixed point is better, because any decimal fixed point ...
user avatar
  • 1,099
1 vote
1 answer
2k views

ERC20 Token convert unit256 format depending on decimal

Hello i am trying to convert unit256 format depending on the decimal value of each token address. Decimal 9 and 18 ı did converted. they work fine as seen in the code below but I don't know what to do ...
user avatar
1 vote
1 answer
134 views

Why do almost all of the ERC20 tokens have even number of decimals?

I'm thinking of creating a token with a decimal point of odd number. However I'm kind of worried if there is any issue that can be caused by using an odd number for the decimal point. Is there any ...
user avatar
  • 196
0 votes
1 answer
273 views

How to calculate the right amount of a token to use in 0x quote endpoint

I'm trying to use 0x to buy tokens with ETH. I'm following the sample at https://0x.org/docs/guides/swap-tokens-with-0x-api#swap-eth-for-1-dai. I got the token address, and the decimals. let's say ...
user avatar
1 vote
1 answer
261 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. ...
user avatar