I want to have a nice way to show sol amounts in my code:

use anchor_lang::solana_program::native_token::LAMPORTS_PER_SOL;

const REWARD: u64 = LAMPORTS_PER_SOL * 0.1; // 0.1 SOL

I am getting this error: help: the trait Mul<{float}> is not implemented for u64

How would I solve that in Rust?

2 Answers 2


Well this works:

const CHEST_REWARD: u64 = LAMPORTS_PER_SOL / 10; // 0.1 SOL

Maybe good enough :D


I understand that the data types they handle are variables, so this function could help you to convert the lamport expressed in u64 to SOL expressed in decimal:

fn lamports_to_sol(lamport: u64) -> f64 {
        let sol: f64 = lamport as f64;
        return (sol / 1000000000.0) as f64
let amount: u64 = 1256541200;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.