//%f表示以十进制格式化输出浮点数

String s1 ="评分: %.1f";

String s2 = String.format(s1, 8.0);

System.out.println(s2);

System.out.printf("%s%n", new Integer(1212));

// %n表示换行

System.out.printf("%s%n", "end line");

// 还能够支持多个參数

System.out.printf("%s = %s%n", "Name", "Zhangsan");

// 支持多个參数时。能够在%s之间插入变量编号,1$表示第一个字符串,3$表示第3个字符串

System.out.printf("%1$s = %3$s %2$s%n", "Name", "san", "Zhang");



Integer iObj = 342;

// %d表示将整数格式化为10进制整数

System.out.printf("%d; %d; %d%n", -500, 2343L, iObj);

// %o表示将整数格式化为8进制整数

System.out.printf("%o; %o; %o%n", -500, 2343L, iObj);

// %x表示将整数格式化为16进制整数

System.out.printf("%x; %x; %x%n", -500, 2343L, iObj);

// %X表示将整数格式化为16进制整数,而且字母变成大写形式

System.out.printf("%X; %X; %X%n", -500, 2343L, iObj);



Double dObj = 45.6d;

// %e表示以科学技术法输出浮点数

System.out.printf("%e; %e; %e%n", -756.403f, 7464.232641d, dObj);





// %E表示以科学技术法输出浮点数。而且为大写形式

System.out.printf("%E; %E; %E%n", -756.403f, 7464.232641d, dObj);

// %f表示以十进制格式化输出浮点数

System.out.printf("%f; %f; %f%n", -756.403f, 7464.232641d, dObj);

// 还能够限制小数点后的位数

System.out.printf("%.1f; %.3f; %f%n", -756.403f, 7464.232641d, dObj);

System.out.printf("%e", 1245f);

//%f表示以十进制格式化输出浮点数 %.2f的更多相关文章

  1. [转载] c++ cout 格式化输出浮点数、整数及格方法

    C语言里可以用printf(),%f来实现浮点数的格式化输出,用cout呢...? 下面的方法是在网上找到的,如果各位有别的办法谢谢留下... iomanip.h是I/O流控制头文件,就像C里面的格式 ...

  2. [ZZ]c++ cout 格式化输出浮点数、整数及格式化方法

    C语言里可以用printf(),%f来实现浮点数的格式化输出,用cout呢...?下面的方法是在网上找到的,如果各位有别的办法谢谢留下... iomanip.h是I/O流控制头文件,就像C里面的格式化 ...

  3. C++格式化输出浮点数

    主要内容 介绍C++中如何格式化输出浮点数. 控制浮点数输出格式需要包含iomanip头文件. 使用fixed来控制输出的浮点数的小数位是固定的.可参考http://en.cppreference.c ...

  4. 7.20.01 java格式化输出 printf 例子

    java格式化输出 printf 例子 importjava.util.Date; publicclassPrintf { publicstaticvoidmain(String[] args) { ...

  5. Java面向对象 第2节 Scanner 类和格式化输出printf

    §Scanner 类 java.util.Scanner 是 Java5 的新特征,我们可以通过 Scanner 类来获取用户的输入. 1.创建 Scanner 对象的基本语法:Scanner s = ...

  6. Java String 函数常用操作 & format() 格式化输出,代码详解

    package _String_; import java.util.*; import java.math.*; import java.lang.*; public class _Strings ...

  7. 【转】java格式化输出 printf 例子

    [转]java格式化输出 printf 例子 转自http://www.cnblogs.com/TankMa/archive/2011/08/20/2146913.html#undefined imp ...

  8. java格式化输出 printf 例子

    import java.util.Date; public class Printf { public static void main(String[] args) { // %s表示输出字符串,也 ...

  9. 【JavaSE】格式化输出

    Java格式化输出 2019-07-06  11:35:55  by冲冲 1. 输出字符串 %s 1 /*** 输出字符串 ***/ 2 // %s表示输出字符串,也就是将后面的字符串替换模式中的%s ...

随机推荐

  1. 独立成分分析 与 功能连接之间的关联尝试 by 张高燕

    在处理fMRI数据时,使用空间ICA的方法.   将一个四维的fMRI数据分解为空间pattern与时间序列的乘积. //这里的pattern=component   其中每一pattern的时间序列 ...

  2. javascript比较两个时间大小

    //var yourtime=document.getElementById('begin_time').value; var yourtime='2010-12-10 11:12'; yourtim ...

  3. koa2搭建服务器+使用mongoose链接mangodb

    使用node搭建服务器,用到了现在比较流行的框架koa. 1.初始化package.json npm init -y 2.安装koa2 npm i koa --save 3.搭建服务器 const K ...

  4. Nuget server on IIS6 returns 404

    Nuget server on IIS6 returns 404 when downloading package after upgrade 2011年9月2日 8:03:30 (GMT Dayli ...

  5. Spring持久化

    1. Spring的DAO理念 Spring提供了一套抽象的DAO类,供开发者扩展,这有利于以统一的方式操作各种DAO技术,如JDO.JDBC等,这些抽象DAO类提供了设置数据源及相关辅助信息的方法, ...

  6. 创建一个简单的windows服务,每间隔一定时间重复执行批处理文件

    创建一个windows服务项目,增加App.config <?xml version="1.0" encoding="utf-8" ?> <c ...

  7. mac下的一些命令

    1.显示隐藏文件 defaults write com.apple.finder AppleShowAllFiles -bool true 2.隐藏隐藏文件 defaults write com.ap ...

  8. dynamic bone unity github

    https://github.com/unity3d-jp/unitychan-crs 我发现我总找不到以前的东西.. https://www.cnblogs.com/alps/p/8284577.h ...

  9. (回溯法)数组中和为S的N个数

    Given a list of numbers, find the number of tuples of size N that add to S. for example in the list ...

  10. (LeetCode 53)Maximum Subarray

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...