You are viewing a single comment's thread from:

RE: Calculating a user's Steemit reputation score in JavaScript [bonus content: an Angular Pipe that does it for you]

in #steemdev7 years ago

You could add a parameter to the pipe to set the decimal precision.

transform(value: number, precision: number) {
  ...
  return reputation.toFixed(precision);
}
Sort:  

Yeah, nice one. I thought about that but I didn't have a use case for it yet myself. I'm not sure if toFixed() is the right solution though, as "officially" the simplified rep should be floored, not rounded.

hmmm... it should be conditional then.

return precision ? reputation.toFixed(precision) : Math.floor(reputation);

Yeah, or something like this:

function toPrecision(value, precision) {
    const multiplier = Math.pow(10, precision);
    return Math.floor(value * multiplier) / multiplier;
}

Coin Marketplace

STEEM 0.20
TRX 0.15
JST 0.030
BTC 65317.17
ETH 2646.03
USDT 1.00
SBD 2.86