Given an integer n, add a dot (".") as the thousands separator and return it in string format.

&nbsp;
Example 1:

Input: n = 987
Output: "987"


Example 2:

Input: n = 1234
Output: "1.234"


&nbsp;
Constraints:


	0 &lt;= n &lt;= 231 - 1


class Solution(object):
    def thousandSeparator(self, n):
        """
        :type n: int
        :rtype: str
        """
        n = str(n)
        if len(n) <= 3:
            return str(n)
        result = ""      
        dot = '.'
        index = 0
        startPos = len(n) % 3 
        if startPos == 0:
            startPos += 3
        val = -1
        while index < len(n):
            result += n[index]
            if index == startPos - 1:
                result += dot
                val = 0
            if val != -1:
                val += 1
                if val > 3 and (val - 1) % 3 == 0 and index != len(n) - 1:
                    result += dot
                    val = 1  
            index += 1

        return result
class Solution {
    public String thousandSeparator(int n) {
       
        StringBuffer str = new StringBuffer(Integer.toString(n));
        int index = str.length() - 3;
        
        while(index >= 1){
            str.insert(index , '.');
            index = index - 3;
        }
        
        return str.toString();
    }
}
class Solution {
public:
    string thousandSeparator(int n) {
        string s="";
        int a=0;
        if(n==0)return "0";
       while(n>0){
           s+=char(n%10+48);
           a++;
           n/=10;
           if(a==3&&n!=0)
           {
               a=0;
               s+=".";
           }
       }
        reverse(s.begin(),s.end());
        return s;
    }
};
var thousandSeparator = function(n) {
    let ans = "";

    if(n >= 1000){
    const arr = String(n).split('');
        for(let i=0;i<arr.length;i++){
            let temp = arr.length - i;
            if(temp === 3 && arr.length > temp || temp === 6 && arr.length > temp || temp === 9 && arr.length > temp || temp === 12 && arr.length > temp){
                ans += '.';
            }
        ans += arr[i];
        }
    }else{
        ans += n;
    }

    return ans;
};
Thousand Separator