# How can I trim long (useless) numbers?

##### Member
Thinkscript allows you to roundup or down the last numbers to your liking, but is there a way to "trim" the front numbers and only see the last x numbers? I test my strategies with chart bubbles showing long numbers like "12345678.90". I would like this to be formatted as "78.90". Or for ES, format 3683.25, 3685.75, 3692.50 to 83.25, 85.75, 92.50, etc.

Solution
Thinkscript allows you to roundup or down the last numbers to your liking, but is there a way to "trim" the front numbers and only see the last x numbers? I test my strategies with chart bubbles showing long numbers like "12345678.90". I would like this to be formatted as "78.90". Or for ES, format 3683.25, 3685.75, 3692.50 to 83.25, 85.75, 92.50, etc.

to trim this
12345678.90
into this
78.90

Code:
``````def x1 = 12345678.90;
# move decimal point left 2
def x2 = x1 / 100;
# remove integer portion
def x3 = x2 - floor(x2);
# shift digits, move decimal point
def x4 = x3 * 100;

Thinkscript allows you to roundup or down the last numbers to your liking, but is there a way to "trim" the front numbers and only see the last x numbers? I test my strategies with chart bubbles showing long numbers like "12345678.90". I would like this to be formatted as "78.90". Or for ES, format 3683.25, 3685.75, 3692.50 to 83.25, 85.75, 92.50, etc.

to trim this
12345678.90
into this
78.90

Code:
``````def x1 = 12345678.90;
# move decimal point left 2
def x2 = x1 / 100;
# remove integer portion
def x3 = x2 - floor(x2);
# shift digits, move decimal point
def x4 = x3 * 100;

to trim this
12345678.90
into this
78.90
Thank you so much! I have another question:

I want to apply your formula to 4 variables (eg. open, high, low, close). How would I do that without writing the formula for each variable?

Last edited:
Thank you so much! I have another question:

I want to apply your formula to 4 variables (eg. open, high, low, close). How would I do that without writing the formula for each variable?

the function, script, can be used to create a sub routine within the main study.
it is used when a collection of formulas, will be used multiple times.

i added an input to choose how many digits to trim to. the default is 2.

Ruby:
``````# trim_digits2_02b

#  "trim" the front numbers and only see the last x numbers
# ex, this number, 12345678.90 , will be changed to  78.90

script trim1 {
# trim the digits left of the decimal point, down to x digits
input x = 0;
input digits = 2;
# move decimal point left 2
def dig = Power(10, digits);
def x2 = x / dig;
# remove integer portion
def x3 = x2 - Floor(x2);
# shift digits, move decimal point
plot z = x3 * dig;
}

# test numbers
#def x1 = 12345678.92;
#def x2 = 12345644.55;
#def x3 = 12345633.77;
#def x4 = 12345611.66;

def x1 = open;
def x2 = high;
def x3 = low;
def x4 = close;

input trim_digits = 2;

def x1_trim = trim1(x1, trim_digits);
def x2_trim = trim1(x2, trim_digits);
def x3_trim = trim1(x3, trim_digits);
def x4_trim = trim1(x4, trim_digits);

#``````

https://tlc.thinkorswim.com/center/reference/thinkScript/Reserved-Words/script

How can I get .0845 to show as 8.5?

87k+ Posts
326 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?