SimpleCryptoLife

[SCL] Significant Figures Example Function

This script consist of a single example function that takes a floating-point number - one that can, but doesn't have to, include a decimal point - and converts it to a floating-point number with only a certain number of significant digits left.

I'm not aware of another script that does this. There might well be a simpler way, in which case please do let me know.

For example, say you want to display a variable from your script to the user and it comes out to something like 45.366666666666666666666667 or whatever. That looks awful when you, for example, print it in a label.
Now, you could round it up to the nearest integer easily using a built-in function, or even to a certain number of decimal places using a reasonably simple custom function.
But that's a bit arbitrary. Suppose you don't know what asset the script will be used on, and so you can't predict what the price is, and what the value will turn out to be.
It could be 0.00045366666666666666666666667 instead. Now if you round it up to 3 decimal places it comes out as 0.000, which is useless.
My function will round that number to 0.0004536 instead, if told to do it to 4 significant digits.

You're free to use this function in your own scripts, including closed-source scripts, without asking permission. Credit to @SimpleCryptoLife would be appreciated.

オープンソーススクリプト

TradingViewの精神に則り、このスクリプトの作者は、トレーダーが理解し検証できるようにオープンソースで公開しています。作者に敬意を表します!無料で使用することができますが、このコードを投稿で再利用するには、ハウスルールに準拠する必要があります。 お気に入りに登録してチャート上でご利用頂けます。

免責事項

これらの情報および投稿は、TradingViewが提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。

チャートでこのスクリプトを利用したいですか?