함수 number_format()

1 개요[ | ]

함수 number_format()

2 Java[ | ]

import java.math.BigDecimal;
public class MyClass {
    public static void main(String args[]) {
        double r = 1234.5678;
        System.out.println(new BigDecimal(r).setScale(2,BigDecimal.ROUND_HALF_UP));
        System.out.println(BigDecimal.valueOf(r).setScale(2,BigDecimal.ROUND_HALF_UP));
        // 1234.57
        // 1234.57
        System.out.println(new BigDecimal(r).setScale(6,BigDecimal.ROUND_HALF_UP));
        System.out.println(BigDecimal.valueOf(r).setScale(6,BigDecimal.ROUND_HALF_UP));
        // 1234.567800
        // 1234.567800
    }
}
public class MyClass {
    public static void main(String args[]) {
        double r = 1234.5678;
        System.out.println(new java.math.BigDecimal(r).setScale(2,java.math.BigDecimal.ROUND_HALF_UP));
        System.out.println(java.math.BigDecimal.valueOf(r).setScale(2,java.math.BigDecimal.ROUND_HALF_UP));
        // 1234.57
        // 1234.57
        System.out.println(new java.math.BigDecimal(r).setScale(6,java.math.BigDecimal.ROUND_HALF_UP));
        System.out.println(java.math.BigDecimal.valueOf(r).setScale(6,java.math.BigDecimal.ROUND_HALF_UP));
        // 1234.567800
        // 1234.567800
    }
}

3 PHP[ | ]

<?php
$num = 1234.5678;
echo number_format($num);
# 1,235
echo number_format($num,2);
# 1,234.57
echo number_format($num,2,'','');
# 123457
echo number_format($num,2,'.','');
# 1234.57
echo number_format($num,6);
# 1,234.567800

4 SQL[ | ]

4.1 MySQL[ | ]

SELECT FORMAT(1234.5678, 0);
# 1,235
SELECT FORMAT(1234.5678, 2);
# 1,234.57
SELECT FORMAT(1234.5678, 6);
# 1,234.567800

5 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}