How to modify value decimals

hello
can i get some help how to convert long decimals to show only 2-5 decimals
long decimals: 0.0149708640498232
short decimal: 0.01497 <-- how can i convert or modify how many decimals i can show

sample code

const fromTokens = contract.methods.fromTokens().send({
      from: ethAddress,
      value: Moralis.Units.ETH(sendAmount),
    });

usually you can use number.toFixed(5)

x = 0.0149708640498232
0.0149708640498232
x.toFixed(5)
'0.01497'

so need to be hardcoded
i thought i can use conversion from wei
like this code

const tokenValue = (value, decimals) =>
        (decimals ? value / Math.pow(10, decimals) : value);
x = Moralis.Units.FromWei(10000000000003214)
0.010000000000003215
x.toFixed(5)
'0.01000'

if i cannot make that work
is it ok if i can use css to modify the decimals?

you can modify them how you want

ok thank you for the info

btw i try css but not look good
about using javascript method how can i apply that code here

x = Moralis.Units.FromWei(10000000000003214)
0.010000000000003215
x.toFixed(5)
'0.01000'
 const nativeTokens = contract.methods.nativeTokens().send({
      from: ethAddress,
      value: Moralis.Units.ETH(sendAmount),
    });

Hey @dcoderk

You can use Moralis.Units.Token(amount, decimals)

do i need to apply like this?

value: Moralis.Units.ETH(sendAmount, decimal(5)),
function f_fixDecimalPlace(_value, _decimals){
    return Function('"use strict";return (' + _value / 10 ** _decimals + ')')();
}

It is always the way when learning to come across many things you have already attempted to make.

Moralis.Units.Token(amount, decimals), very good :smiley: