---
title: "确定小数点后面的数字个数"
author: "thoughtfly"
date: "2009-11-16T09:16:30Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2009-11-16T09:16:30Z"
id: 517859
url: "https://thoughtfly.iteye.com/blog/517859"
---

```
DecimalFormat df2 = new DecimalFormat("####.000");
            System.out.println(df2.format(1234.56));
        }
    }
```

 

在这个例子中设置了数字的格式，使用像"####.000"的符号。这个模式意味着在小数点前有四个数字，如果不够就空着，小数点后有三位数字，不足用0补齐。程序的输出：

    1234.560

 

 其中#是数字的代替，也可只用一个#,也可用".000"