Function Number2Currency

Function Number2Currency

I built a Function that formats numbers with commas for readability. I use it when I include numbers in an email or a screen field that is display only. I could not find any similar built in function in Zoho. Feel free to use this in your own applications.


// This function converts a number to a string with the appropriate commas
// Example Tot_Value_Str = thisapp.Number2Currency(Tot_Value);
// If Tot_value = 1234567 then Tot_Value_Str will be formated as 1,234,567.00
// Herb Wexler 1/14/09


string Number2Currency(float number_in)
{
    input.number_in = input.number_in.round(0);
    String_Out = input.number_in.toString();
    Tot_Len = (String_Out).length();
    Start_Index = (Tot_Len  -  3);
    if ((Tot_Len  >  3)  &&  (Tot_Len  <  7))
    {
        String_Out = (((String_Out).subString(0,(Tot_Len  -  3))) + ",") + (String_Out).subString(Start_Index,Tot_Len);
    }
    else if (Tot_Len  >  6)
    {
        String_Out = (((((String_Out).subString(0,(Tot_Len  -  6))) + ",") + (String_Out).subString((Start_Index  -  3),(Tot_Len  -  3))) + ",") + (String_Out).subString(Start_Index,Tot_Len);
    }
    return String_Out;
}


























Herb Wexler
www.preventingmediocrity.com