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.

Script open-source

Dans le véritable esprit de TradingView, l'auteur de ce script l'a publié en open-source, afin que les traders puissent le comprendre et le vérifier. Bravo à l'auteur! Vous pouvez l'utiliser gratuitement, mais la réutilisation de ce code dans une publication est régie par le règlement. Vous pouvez le mettre en favori pour l'utiliser sur un graphique.

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.

Vous voulez utiliser ce script sur un graphique ?