Unit Conversion
Basic conversions
// Convert STX to microSTX
function stxToMicroStx(stx: number | string): bigint {
const stxAmount = typeof stx === 'string' ? parseFloat(stx) : stx;
return BigInt(Math.floor(stxAmount * 1_000_000));
}
// Convert microSTX to STX
function microStxToStx(microStx: number | bigint | string): string {
const amount = BigInt(microStx);
const stx = Number(amount) / 1_000_000;
return stx.toFixed(6).replace(/\.?0+$/, '');
}
// Usage examples
const microStx = stxToMicroStx(1.5); // 1500000n
const stx = microStxToStx(1500000); // "1.5"Precision-safe handling
Token conversions
Display formatting
Last updated
Was this helpful?