Questions tagged [decimals]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
12 views

Using decimals in intermediate calculations?

I'm looking at a contract that takes a uint88 and divides by the product of a uint80 and a uint104. The uint80 is the inverse of ETH/USDC (ie, it is the price of one USDC in terms of ETH)...obviously ...
auditor_chick's user avatar
0 votes
0 answers
9 views

What happens if you divide a uint256 by a uint88 using divU64?

I am looking at the following function. It takes a uint256 (ercDebtSocialized) and uses safemath divU64 to divide it by a uint88. I assume this would just throw an error? I unfortunately cannot test ...
auditor_chick's user avatar
4 votes
2 answers
81 views

Why uint8 for decimals in ERC20 tokens?

Is there a specific reason why pretty much everyone uses uint8 for the decimals in ERC20 tokens? I would get it if it was to limit the size, because the decimals will never be big enough to exceed the ...
Andy's user avatar
  • 185
3 votes
1 answer
29 views

Issue with sending tokens after performing arithmetic operations

I'm implementing a fundraising contract where a user can create a fundraiser but when creating they must send a rewardingToken (ERC20 token) to the contract and the user also specifies a token which ...
stringRay2014's user avatar
2 votes
2 answers
160 views

Strategy in saving and displaying ETH decimal places

What is your strategy for storing and displaying decimal places for ETH? I noticed most exchanges use only 4 (Binance) to 8 (CEX) decimal places when displaying ETH amount. What is your take? And do ...
ratib90486's user avatar
0 votes
1 answer
73 views

Can't make it compatible with 9 decimals tokens (newbie question)

I'm trying to fork a miner contract. Everything works fine with 18 decimals tokens, but I just can't make it work with 9 decimals tokens (which is the main target of what I'm trying to do). The ...
WannabeDev's user avatar
0 votes
1 answer
172 views

Why does chainlink price feed use 8 as decimal in USD pairs? [duplicate]

I am trying to implement Chainlink's price feed in my contract. I've learned that when using the USD pair, it always uses 8 as the decimal. I am curious as to why 8 is used instead of 18, is there a ...
mingg's user avatar
  • 1
0 votes
0 answers
94 views

Etherscan Shows Token TotalSupply with all 18 Decimals. Why?

I just deployed the token smart contract and Etherscan shows the TotalSupply with all 18 decimals for some reason. Basically, it shows excessive 18 zeroes in the TotalSupply section. Could you please ...
newcontractor's user avatar
1 vote
1 answer
61 views

Any known ERC20 Tokens that don't implement the decimals() function?

Are there any ERC20 Tokens that don't implement the decimals() functionality?
andreitoma's user avatar
1 vote
1 answer
272 views

I dont understand how to use ABDKMath64x64 for mul and div

If i console.log this ABDKMath64x64.add(3, 2); I get the result of BigNumber { value: "5" } which is correct. But ABDKMath64x64.mul(3, 2); returns BigNumber { value: "0" } and ...
damdafayton's user avatar
0 votes
1 answer
145 views

What should be the decimals for ERC20 token when you want to deploy in Solana network using NeonEVM?

I'm trying to get my head around the concept of this decimal in Eth. Should I change the decimals when I want to deploy outside of the Ethereum network? What would be the correct decimals value when I ...
Yosuke Sakurai's user avatar
1 vote
1 answer
676 views

What is the best way to divide BN by a decimal?

I am using ethers npm library to divide BN by a decimal. The account(0x..) has 10.99999 GLD. const {ethers} = require('ethers'); const token = myGoldContract.balanceOf('0x....').toString(); console....
Avinash Kulal's user avatar
1 vote
0 answers
17 views

I created a custom token in my wallet and sent tokens to it after the didn't show up I I put wrong decibel can it be fixed? [closed]

Trust wallet etherscan shows coins to bi in my wallet with the rest of my coins But wallet shows no coins for the one I made custom token I put 12 decibel instead of 9 how can I fix this?
Terry Beets's user avatar
0 votes
3 answers
806 views

Uniswap V2, getAmountsOut and toWei/fromWei

I have a simple code to get prices from Uniswap V2 const getTokenExchangeRate = async (tokenA, tokenB) => { return ( await dexRouter.methods.getAmountsOut(toWei("1"), [tokenA, ...
Viktor Cortez's user avatar
0 votes
0 answers
26 views

How do I remove decimals from a uint256 [duplicate]

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 = ...
Pim Hakkert's user avatar
0 votes
1 answer
27 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?
Paul Razvan Berg's user avatar
0 votes
1 answer
165 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 ...
satrio galih's user avatar
0 votes
0 answers
19 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 ...
ian3111's user avatar
0 votes
1 answer
116 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, ...
leojail's user avatar
  • 167
5 votes
1 answer
3k 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?
caker's user avatar
  • 145
1 vote
1 answer
222 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 ...
Dominic's user avatar
  • 117
0 votes
1 answer
1k 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 )....
Koby Adu-Bonnah's user avatar
1 vote
1 answer
738 views

How convert hex number to decimal in solidity? [duplicate]

I would like to convert a hex number to decimal.
Amirali Sahraei's user avatar
0 votes
2 answers
3k 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....
M4theuz's user avatar
  • 101
0 votes
0 answers
1k 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 ...
Mikhail Janowski's user avatar
1 vote
1 answer
81 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
doğa özcan's user avatar
1 vote
1 answer
713 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 ...
swapnil dhamal's user avatar
3 votes
2 answers
2k 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 ...
bbusdriver's user avatar
  • 1,084
2 votes
2 answers
2k 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 ...
JTCon's user avatar
  • 683
1 vote
0 answers
1k 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 ...
nora goba's user avatar
0 votes
1 answer
170 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 ...
sauravs24's user avatar
1 vote
1 answer
955 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 ...
Bob5421's user avatar
  • 1,433
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 ...
Gökhan Özdemir's user avatar
1 vote
1 answer
191 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 ...
bbnn's user avatar
  • 206
0 votes
1 answer
353 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 ...
Traveling Tech Guy's user avatar
1 vote
1 answer
388 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. ...
Patrick Collins's user avatar