Skip to content

Best way to initialize a fractional fixed point value. #45

Closed Answered by PaulRBerg
joaomontenegro asked this question in Q&A
Discussion options

You must be logged in to vote

Hey! There are multiple ways to do this, as there is a multitude of conversion function shipped with PRBmath.

Scientific Notation

// 0.5
UD60x18 foo = ud(0.5e18);
UD60x18 foo = ud60x18(0.5e18);
UD60x18 foo = wrap(0.5e18);

"To" Conversion Function

This only works for whole numbers greater than or equal to 1e18. See the NatSpec comments for the toUD60x18 for more details on how this works.

// 50
UD60x18 foo = toUD60x18(50);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by PaulRBerg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants