thinkScript AsPrice() helps remove comma for sorting

beeper212

New member
I'm trying to print out the date and time on my chart as a label. I'm 80% but I'm having a problem with GetYear function.

When I use this code:

Code:
AddLabel (yes, GetYear (), Color.YELLOW);

My Output says "2,020" instead of "2020". Is there a function to remove the comma? Or to specific that I don't the number to print with commas?

Thank you
 
Solution
@rad14733 - did you try the AsPrice() method? It does what @beeper212 wanted - removes the comma and leaves a simple "2020".

@beeper212 Here is a label that shows the day of the week and the date, taken from the the TSL OneNote ( https://tinyurl.com/tsCommunity ) -
Code:
# Day of Week and Date Label
# MrScript
# via JQ's OneNote

def Day = GetDayOfWeek(GetYYYYMMDD());
def Month = GetMonth();
def Date = GetDayofMonth(GetYYYYMMDD());
def year = (Round(GetYYYYMMDD() / 10000, 0));

AddLabel(Day==1,concat("Monday   "+Month+"/",Date+"/"+AsPrice(Year)),color.white);
AddLabel(Day==2,concat("Tuesday   "+Month+"/",Date+"/"+AsPrice(Year)),color.white)...

rad14733

Well-known member
VIP
TOS does not have any manipulation functions to do that, that I am aware of... And the code below will remove the comma but adds decimals which Round() won't remove...

Ruby:
AddLabel (yes, AsText(GetYear()), Color.YELLOW);
 

rad14733

Well-known member
VIP
Nope...!!! TOS doesn't have any text manipulation functions... I've tried AsText() and a few other functions to no avail... The best I could do was AsText() which turns 2,020 into 2020.00... Round() won't work on text so that's a no-go as well...
 

Pensar

Well-known member
VIP
@rad14733 - did you try the AsPrice() method? It does what @beeper212 wanted - removes the comma and leaves a simple "2020".

@beeper212 Here is a label that shows the day of the week and the date, taken from the the TSL OneNote ( https://tinyurl.com/tsCommunity ) -
Code:
# Day of Week and Date Label
# MrScript
# via JQ's OneNote

def Day = GetDayOfWeek(GetYYYYMMDD());
def Month = GetMonth();
def Date = GetDayofMonth(GetYYYYMMDD());
def year = (Round(GetYYYYMMDD() / 10000, 0));

AddLabel(Day==1,concat("Monday   "+Month+"/",Date+"/"+AsPrice(Year)),color.white);
AddLabel(Day==2,concat("Tuesday   "+Month+"/",Date+"/"+AsPrice(Year)),color.white);
AddLabel(Day==3,concat("Wednesday   "+Month+"/",Date+"/"+AsPrice(Year)),color.white);
AddLabel(Day==4,concat("Thursday   "+Month+"/",Date+"/"+AsPrice(Year)),color.white);
AddLabel(Day==5,concat("Friday   "+Month+"/",Date+"/"+AsPrice(Year)),color.white);
AddLabel(Day==6,concat("Saturday   "+Month+"/",Date+"/"+AsPrice(Year)),color.white);
AddLabel(Day==7,concat("Sunday   "+Month+"/",Date+"/"+AsPrice(Year)),color.white);
 
Solution
Top