Bug Fix: ToFixed Without Rounding in Steem-Engine

in #utopian-io5 years ago

Introduction

This is a proper fix as to previous PR

The function formatSteemAmount will not have 3 decimal places for input values less than 3 decimal places. For example, formatSteemAmount(3.1) will return "3.1"

image.png

This will be a problem for steem-js as it is expecting exactly 3 digits.

Therefore, I have made a function that does exactly this purpose: preserve 3 decimal places without rounding: see my blog: https://helloacm.com/javascripts-tofixed-implementation-without-rounding/

Pull Request

https://github.com/MattyIce/steem-engine/pull/77

How I Implement it?

I implement the Number's prototype function toFixedNoRounding that will first convert the number into string, and use regex to grep at most 3 digits.

image.png

Next, I will search for the dot position and repeat zeros if not enough.


If you believe what I am doing, please consider a spare vote voting me here, thank you very much indeed.

@justyy - the author of https://SteemYY.com and I have been a Steem Witness for more than a year now.

Sort:  

Simple and efficient implementation. Great touch. 👍


Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Chat with us on Discord.

[utopian-moderator]

Thank you for your review, @emrebeyler! Keep up the good work!

Hi @justyy!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 5.287 which ranks you at #779 across all Steem accounts.
Your rank has improved 8 places in the last three days (old rank 787).

In our last Algorithmic Curation Round, consisting of 161 contributions, your post is ranked at #116.

Evaluation of your UA score:
  • You've built up a nice network.
  • The readers appreciate your great work!
  • Try to work on user engagement: the more people that interact with you via the comments, the higher your UA score!

Feel free to join our @steem-ua Discord server

Hey, @justyy!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.20
TRX 0.18
JST 0.031
BTC 90574.88
ETH 3192.52
USDT 1.00
SBD 2.90