209 похожих чатов

Как правильно округлить число до целочисленного в солидити?

8 ответов

31 просмотр

в солидити числа все целочисленные

А откуда у Вас нецелое число? Fixed point можно только константами задавать. Или уже обновление завезли?

M-Developer Автор вопроса
Dmitriy Gogolev
в солидити числа все целочисленные

а если я делю и получаю не целое?

deepcode.eth • Roman P
А откуда у Вас нецелое число? Fixed point можно то...

не будет такого обновления в ближайшее время

M-Developer Автор вопроса
Dmitriy Gogolev
4/3 = 1

он сам округляет?

/** * Calculate fee (UnSafeMath) -- use it only if it ^0.8.0 * @param amount number from whom we take fee * @param scale scale for rounding. 100 is 1/100 (percent). we can encreace scale if we want better division (like we need to take 0.5% instead of 5%, then scale = 1000) */ function calculateFee(uint256 amount, uint256 scale) internal view returns (uint256) { uint a = amount / scale; uint b = amount % scale; uint c = promille_fee / scale; uint d = promille_fee % scale; // Calculate fee with ROUND DOWN // return a * c * scale + a * d + b * c + b * d / scale; // calculate fee with ROUND UP // return a * c * scale + a * d + b * c + (b * d + scale - 1) / scale; // I guess we use this //calculate fee with CLOSESTS INTEGER // return a * c * scale + a * d + b * c + (b * d + scale / 2) / scale; return a * c * scale + a * d + b * c + (b * d + scale - 1) / scale; } чекни этот пример

Похожие вопросы

Обсуждают сегодня

Ready for some fun AND a chance to win TKO Tokens? Join us for exciting minigames in our Telegram group! 🕒 Don’t miss out—games start on today 25 October 2024, at 8 PM! Ge...
Milkyway | Tokocrypto
255
How are we going bro about the Raids ??
🅿️abby_FX
13
Keep saying it, it’s Trump or WW3. Iran will be emboldened if Harris wins by cheating. Israel will have to take the initiative against Iran. How has BTC faired everytime the...
Adz | Ferrum Network Product & Service Consultant @ Ferrum Network
1
------------------------------------------------------------------------------ 📢 MAJOR ANNOUNCEMENT: HSUITE ECOSYSTEM UPDATE 📢 @everyone Dear HbarSuite Community, After month...
Big Stones
3
Ok I will use this example…there has been a crazy amount of meme coins launched on solana and more recently on xrp ledger, many of these memes have found their way on to diffe...
Stevo Payne
7
isnt that how its called? lol
Hobbyist
34
Hey guys, I am a first time Staker, I'm on Chrome browser on Hex dot com, I'm using rabby wallet with my ledger nano X, but when I click the STAKE button it doesn't prompt my ...
Slug
8
Does anyone in here have a contact with EOS Labs that we could ask what they've been doing with their funding?
Bytecode360 Katoshi [1337 f4rm3r]
13
I know it does. The thing is in my case for example, I'm not using desktop (secure VM) for anything else besides nautilus. Even my bank pushed me towards mobile app, they do n...
Navip
2
Cake wallet beta works on Linux?? Anybody?
MR V
7
Карта сайта