How to format this number in Javascript?

Asked

Viewed 28 times

0

I am creating a small system that works with Bitcoins, for those who do not know, the bitcoin has the following format (0.00000000), this is my mini-system:

//neste caso, o bet = 0.00000001 e o inc 150

var bet    = $('#btc').val();

// este inc é um incremento em porcentagem
var inc    = $('#inc').val();

//aqui o inc é transformado em decimal para facilitar
var vbet   = inc/100;

// aqui eu multiplico o bet por 100 milhoes para transforma-lo em numero inteiro
bet        = bet * 100000000;

vbet       = bet + (vbet * bet);

vbet       = Math.round(vbet);

// aqui o valor é novamente transformado em btc dividindo por 100 milhoes
vbet       = vbet / 100000000;

alert(vbet);
// porém o valor que aparece no alert é 3e-8

I need help to format this number, in php I use number_format(number, casas_decimal), there is some js function that does the same thing?

  • I believe you already have something on the net

  • I tried to look, but I didn’t, maybe because I don’t know the right terms to look for, I’m on hold!

  • 1

    I think the emanuelsn answer already satisfies (?), see: https://jsfiddle.net/hhwwyxfq/

  • 1

    perfect, very obg!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.