# Round Up Zero digits after decimal

#### GPM

##### New member
I am new to this forum and also new to Think Or Swim. I did a search and could not find answers to my questions so trying a new post. Hope someone can help me.

1) In my watchlist, I am using there pre-built %Change column. It shows me percentage change in price since previous trading days' close. But I cannot find the prebuilt column names for "previous day close price" and "dollar change" since yesterday's close.

2) I want to create custom columns for "dollar change" and "%Change" and want to show rounded up values.. How do I round up so that my custom columns show zero digits after the decimal. Thus for example, if I have a number 123.45 I want to show it as 123, and if I have 12345.67 I want to show it as 12346. If zero digits is not possible, I can live with 123.0 (which seems to work when I say round (num, 0)

3) Same thing with PE ratio. Is there a way to refer to the pre-built watch list column called Price/Earnings Ratio when I am writing a custom think Script column?

thank you.

@kmg526 Here is the code I use for my ATR Chart Label...

Ruby:
# ATR_Label
input atrLength = 13;
input atrAverageType = AverageType.WILDERS;
def atr = Round(MovingAverage(atrAverageType, TrueRange(high, close, low), atrLength), 2);
AddLabel(yes, "ATR: " + Round(atr, 2), Color.LIGHT_GRAY);
# END ATR_Label
Yeah! TY

Hi,

I am looking for coding that given the following formula would stipulate that the remainder be a whole number:

xnumber / 5 = whole number remainder

For instance: 40/5 = 8 (meets criteria)
39/5 = 7.8 (does not meet criteria)

This I would use to stipulate a specific color for a specific price level.

Thanks for any help.

Bob

@rlohmeyer You can try result/round(result, 0) == 1 so it checks for integer only.

@generic
Thank you very much. Seems simple now, but I just could not get my head around it.

@rlohmeyer Was that what you were looking for? Let me know if you need any more help.

@generic

It was exactly what I was looking for. And thankyou for your offer. I am working to learn Thinkscript as I use it on my trading charts. Your code I used in this indicator:

It was used to identify and color price levels that are rounded to integers of 5, so they are clearly identifiable on the minute chart I trade for a specific stock. The interval (integer) might change based on the instrument, but the indicator gives me a way to specify the integer, (and thus price level) I am looking to emphasize.

Again, thanks. This was the last thing I needed in order finish the indicator and post.

Regards,
Bob

I am new to this forum and also new to Think Or Swim. I did a search and could not find answers to my questions so trying a new post. Hope someone can help me.

1) In my watchlist, I am using there pre-built %Change column. It shows me percentage change in price since previous trading days' close. But I cannot find the prebuilt column names for "previous day close price" and "dollar change" since yesterday's close.

2) I want to create custom columns for "dollar change" and "%Change" and want to show rounded up values.. How do I round up so that my custom columns show zero digits after the decimal. Thus for example, if I have a number 123.45 I want to show it as 123, and if I have 12345.67 I want to show it as 12346. If zero digits is not possible, I can live with 123.0 (which seems to work when I say round (num, 0)

3) Same thing with PE ratio. Is there a way to refer to the pre-built watch list column called Price/Earnings Ratio when I am writing a custom think Script column?

thank you.
Use this type of styling, this is an example for showing volume average of 10 days

def avgVol = Average(volume, 10);

To piggyback off of this older conversation, I am trying to round price lines on my chart to the nearest tick value (for futures).

Right now I am using:
Code:
Round(value, ticksize());

The value seems to round to the nearest point, not tick.

Any suggestions?

To piggyback off of this older conversation, I am trying to round price lines on my chart to the nearest tick value (for futures).

Right now I am using:
Code:
Round(value, ticksize());

The value seems to round to the nearest point, not tick.

Any suggestions?

Here is one way

Ruby:
#Example_MovingAverage_Round_to_Ticksize
plot x = ExpAverage(close, 9);
#Normal rounding
#Round to Ticksize
AddLabel(1, Round((x / TickSize()), 0) * TickSize(), Color.WHITE);

Hello Everyone
I am new at coding, I know enough to be very dangerous, My question is there a way to round up to the nearest whole number in the code like you can in Excel ?

For anyone who wants zero decimal places in your watchlist column, just replace your Plot with AddLabel and then utilize the Round function.
The downfall is the text appears white and can't be changed. It prevents me from using it on a column with dynamic background coloring.
EDIT- it also seems to mess up the sort, so not very useful.

Last edited:
For anyone who wants zero decimal places in your watchlist column, just replace your Plot with AddLabel and then utilize the Round function.
The downfall is the text appears white and can't be changed. It prevents me from using it on a column with dynamic background coloring.
EDIT- it also seems to mess up the sort, so not very useful.

sort text in a column
post2

font color in a column
post103

Last edited:
WINNER from the above answers for Question #2 above on removing unnecessary decimal points:

Code:
(this rounded 49.95 to 49 in a table in MarketWatch).

You can also use Round(MY_VAR, 1) for one more digit, but unfortunately it doesn't add a ".0" if it rounds up to a zero.
The two and three digit scenarios are already covered by native ThinkScript functions.

I would like to only display 1 decimal in a label in a chart.

I'm using the label in a chart & setting the round to 1 this doesn't work as expected--2 decimals are always displayed no matter what rounding number I choose:

When I use AsText, two decimals are always displayed.

How do I round to 1 decimal place only? If that's not possible how do I truncate to 1 decimal place?

Thanks!

I would like to only display 1 decimal in a label in a chart.

I'm using the label in a chart & setting the round to 1 this doesn't work as expected--2 decimals are always displayed no matter what rounding number I choose:

When I use AsText, two decimals are always displayed.

How do I round to 1 decimal place only? If that's not possible how do I truncate to 1 decimal place?

Thanks!

your example code works fine when my_var = 4444/7

post your complete code, so others can see what you are really doing.

Hellow,

Try this code:

87k+ Posts
84 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?