Bug Fix: ToFixed Without Rounding in Steem-Engine

Bug Fix: ToFixed Without Rounding in Steem-Engine

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.


This page is synchronized from the post: ‘Bug Fix: ToFixed Without Rounding in Steem-Engine ‘

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×