jQuery & script

[Script]숫자 한국 원단위 변환

포카리s 2017. 11. 21. 09:12
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function priceToKorPrice(sourcePrice) {
    var targetPrice = "";
    var parsePrice = parseFloat(sourcePrice);
    var multiValue = 10000;
    var multiText = '';
 
    var result = Math.floor(parsePrice / 1000000000000);
    var result0 = Math.floor(parsePrice / 100000000);
    var result1 = Math.floor(parsePrice / 10000);
    var result2 = Math.floor((parsePrice - (result1 * 10000))/1);
 
    if (result > 0) {
        targetPrice += result.toString() + '경';
    }
    if (result0 > 0) {
        if (result0 > 9999) {
            result0 = result0.toString().substring(result0.toString().length, result0.toString().length - 4);
        }
        if (parseFloat(result0) > 0) {
            targetPrice += result0.toString() + '조';
        }
    }
 
    if (result1 > 0) {
        if (result1 > 9999) {
            result1 = result1.toString().substring(result1.toString().length, result1.toString().length - 4);
        }
        if (parseFloat(result1) > 0) {
            targetPrice += result1.toString() + '억';
        }
    }
 
    if (result2 > 0) {
        targetPrice += result2.toString() + multiText;
        return targetPrice + '만원';
    } else {
        return targetPrice + '원';
    }
 
}
cs


'jQuery & script' 카테고리의 다른 글

[Script] 숫자만 입력받기  (0) 2017.11.21
Select Box Option 동적 추가 , 삭제 , 복사  (0) 2017.04.04