Remove the comma from GetYear () function?

B

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,

Beeper212
 
rad14733

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);
 
B

beeper212

New member
Hmmm.... Maybe I can take it letter by letter and only use the first 4 letters to get "2020". I will post my results.

Thanks,

Beeper
 
P

Pensar

Active member
VIP
Maybe try using AsPrice() instead of AsText()? - AddLabel(1, AsPrice(GetYear()), color.white);
 
Last edited:
rad14733

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...
 
P

Pensar

Active 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);
 
P

Pensar

Active member
VIP
@rad14733 I've been stumped many times myself by something simple that I overlooked - glad to know I'm not the only one! :D
 
rad14733

rad14733

Well-known member
VIP
@rad14733 I've been stumped many times myself by something simple that I overlooked - glad to know I'm not the only one! :D
Truth be known, I thought AsPrice formatted in currency format like $123.45... Silly me...
 

Similar threads

Top