does anyone know how i can get decimals in solidity? I have price for nft with type value as uint256. I need it so that people can se the price for their nfts, e.g 0.03 or 0.2 etc.

Dec 15, 2021, 4:53 PM
From the token contract
Solidity doesn’t support decimals natively
Dec 15, 2021, 4:54 PM
In solidity you can specify fractional ether amounts like this:

uint256 price = 0.03 ether;
which of course then gets stored as an integer (wei amount)
Dec 15, 2021, 4:57 PM
hmm right now i have a struct, with price having value of uint256. Whenever i use price in a function, and put 0.2 it throws an error. So how would i fix this? have a modifier that changes the price to ether and returns that?
Dec 15, 2021, 5:00 PM
for function params you just specify the price in wei (not ether)
Dec 15, 2021, 5:01 PM

© 2024 Draquery.com All rights reserved.