数字的格式化

JAVA 中数字格式化总结 在Java中,数字格式化是一项非常常见且重要的功能,它允许开发者以特定的格式展示数字,无论是整数、浮点数、百分比还是货币值等。 阅读详情
 
数字的格式化
在很多情况下需要对输出的信息进行格式化,尤其是当输入的内容为数字的时候,需要按照特定的格式进行输出。另外对运行的结果可能需要进行特殊的处理,例如结果只保留小数点后两位。对数字进行格式化可以使用下面的两个类:
java.text.DecimalFormat
java.text.NumberFormat
NumberFormat是抽象类,所有主要使用DecimalFormat完成格式化。通常使用DecimalFormat的构造函数来生成格式,例如:
NumberFormat nf = new DecimalFormat("0.00");
表示数字的格式为小数点后保留两位,如果整数部分为0,0不能省略,小数点后即使是0也不能省略。
10.374           ——〉           10.37
另外一个符号“#”表示如果一位数字,如果是0,不显示。下面的例子使用了“#”并且整数部分,每3位中间使用“,”隔开。
NumberFormat nf2 = new DecimalFormat("###,###,###.##");
下面是两种格式的不同格式结果:
              NumberFormat nf = new DecimalFormat("0.00");
              a = Float.parseFloat(nf.format(a));
 
数字格式化:你所想的基本可以实现 功能描述: 1.可以保留小数点后几位,如果不足,补0 如果足,就四舍五入 2.整数和小数的逗号分割 立即下载

相关推荐

系统安装、qt配置、安装pcie驱动

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 安装Linux系统指定:ununtu20.04并配置相关软件环境 前言 提示:这里可以添加本文要记录的大概内容: ununtu20.04、Qt 5.9.0、pcie驱动 提示:以下是本篇文章正文内容,下面案例可供参考 一、安装系统 制作系统盘(win10),在开机时按相应键进入BIOS,(华硕需要先改配置启动->CSM->开启->第一个选项选第一个或第二个),等待即可 进入后按照https://www.sysgeek.

weixin_44832804的博客 2206

Java数字处理类--数字格式化

为了解决例如数学问题、随机问题、商业货币问题、科学技术问题等数字处理问题,Java提供了许多数字处理类,包括:】用于格式化数字;】为各种数学计算提供了工具方法;】为处理随机数问题提供了各种方法;】与【】为所有大数字的处理提供了相应的数学运算操作方法。

qq_40132294的博客 1342

WPS用户看过来:避开格式错乱坑,用WPS Office完美制作红头文件(2024最新版)

本文详细解析了WPS Office与Word在红头文件制作中的核心差异,提供了2024年最新版的零误差实战指南。从字体处理、页面布局到红头制作关键步骤,帮助用户避开格式错乱坑,确保跨设备显示一致。特别针对WPS用户优化,解决字体丢失、版式错位等常见问题。

weixin_26800111的博客 218

java中的数字的格式化(超详细)

数字的格式化在解决实际问题时使用非常普遍,如显示某超市的商品价格,需要保留两位小数。// %.2f %.表示 小数点前任意位数 2 表示两位小数 格式后的f表示浮点型。// 设置显示的数字位数 为格式化对象设定小数点后的显示的最多位,显示的最后位四舍五入。// 方法一 :DecimalFormat转换最简便 #.00 表示两位小数。// 方法五 使用格式化数字类 NumberFormat。// 方法三 String.format打印最简便。// 方法二:模仿C语言的输出方式。

m0_74000148的博客 5978

深入解析uncompyle6反编译pyc文件及常见错误修复指南

本文深入解析了使用uncompyle6工具反编译Python字节码文件(.pyc)的完整流程。针对实践中最高频的KeyError和Python版本范围限制两大错误,提供了详细的修复方案与步骤指南,并分享了处理复杂反编译结果的高级技巧与安全实践,是进行代码恢复、调试与分析的重要参考。

uber9的博客 536

ESP32Servo库驱动SG90舵机:从入门到精准控制

本文详细介绍了如何使用ESP32Servo库驱动SG90舵机,从硬件连接到软件环境搭建,再到编写示例程序实现精准控制。内容涵盖库安装、基础驱动代码解析、舵机校准方法以及平滑运动控制,帮助开发者快速掌握ESP32控制舵机的核心技能,并提供了电源管理、信号抗干扰等实用避坑指南。

ik678901的博客 899

数字的格式化(包括占位、居中)

根据需要,可以设置左对齐,符号为<;根据需要,我们会有不同的数字格式输出需求。四、可以设置数字的输出方式,如二进制b,八进制o,十进制d,十六进制X。如上图所示,占位10个字符,并且默认右对齐。代码显示保留2位小数。

xiaojuan13146的博客 488

物联网技术(AIR780E cat1-4G模块+小程序+腾讯云MQTT)驱动的智能井盖系统设计(连载01)

终端设备采用AIR780E模块作为主控器,电子模块有三轴加速度传感器、可燃气体传感器,AIR780E模块(4G模块)通过MQTT通信协议进行数据打包上传至EMQX服务器,在EMQX服务器中,用户可以自行订阅主题和发布主题,小程序通过MQTT通信协议订阅EMQX服务器的主题,服务器通过接收到硬件发布的数据,转发到微信小程序。

leida_3669的博客 2218

properties配置文件读取工具类

properties配置文件读取工具类     本文中将首先介绍一下读取properties配置文件的几种方式,然后详细介绍基于java.util.ResourceBundle的propertiesUtil工具类写法。 一、Java读取properties配置文件的方法,总的来说有3种: 1、基于ClassLoder读取配置文件 Properties properties = new P...

weixin_42315600的博客 1146

当启动容器的时候提示:exec format error?如何解决问题

Docker容器出现"exec format error"的主要原因是架构不兼容(如ARM设备运行x86镜像)。解决方案包括:1)匹配镜像与宿主机架构;2)构建时指定平台;3)安装QEMU模拟器;4)修复文件权限和格式;5)验证基础镜像兼容性。排查流程应从检查架构匹配开始,逐步验证权限、解释器和换行符等问题。建议优先使用多架构镜像,构建时明确指定平台,并使用buildx工具生成多平台镜像。调试时可进入容器手动验证文件格式和兼容性。

weixin_39291964的博客 2721

基于STM32设计的掌上游戏机(运行NES游戏模拟器)详细开发过程

利用STM32单片机移植NES游戏模拟器,完成NES游戏开发,可以玩标准的NES游戏,已测试超级玛丽、魂斗罗之类的都可以正常运行。

4万+

Properties配置文件读取工具类

Properties配置文件读取工具类

Cool.R的博客 238

RT-DETR训练自己的数据集(从代码下载到实例测试)

在Windows10上配置CUDA环境教程是百度提出的一种实时目标检测模型。RT-DETR采用了与DETR相同的编码器和解码器结构,但对其进行了大量的优化,在保持较高检测精度的同时,实现了实时目标检测,为目标检测领域提供了一种新的有效解决方案,具有广泛的应用前景,如自动驾驶、智能监控、机器人等领域。以上是RT-DETR官方的论文和代码,详细介绍了RT-DETR的构成和实现。在YOLOv10中也实现了RT-DETR的代码,所以本文使用YOLOv10的项目文件进行RT-DETR的训练和测试。YOLOv10。

Limiiiing的博客 4万+

读取properties配置文件工具类

读取properties配置文件工具类 package com.cg.utils; import java.io.InputStream; import java.util.Properties; import jdk.internal.org.objectweb.asm.commons.StaticInitMerger; /** * 读取properties配置文件工具类 * @author dfs * */ public class PropertyUtils { private sta

qq_24790827的博客 201

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

JDBC读取Properties配置文件的Utils工具类

通过工具类去读取配置文件,然后避免反复调用数据库连接对象,所以用static关键字,然后通过Properties集合的getProperty方法通过key获得value,最后返回数据库连接对象,获得连接。 package cn.itcast.jabcutil; import java.io.IOException; import java.io.InputStream; impo...

ls_wifi的博客 717

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

读取Properties配置文件的工具类

读取Properties配置文件的工具类

石磊的博客 427

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

读取properties配置文件的方法 还有打包成工具类;

package reflect; import java.io.IOException; import java.io.InputStream; import java.util.Properties; /** * 我们使用反射来读取配置文件的信息 */ public class Reflect { public static void main(String[] args) ...

qq_38053395的博客 319

读取properties配置文件中属性的值的工具类

自制读取properties配置文件的工具类 项目中常用的一些配置的维护,例如redis的ip,数据库ip这些一点是用文件维护起来,方便项目开发时进行调试,为了方便以后使用,就直接封装了一个工具类以便使用,代码如下: /** * 读取properties配置文件中属性的值的工具类 * @author zzx */ public class ReadPropertiesUtils { ...

oneTreeTallTall 787

读取Properties配置文件工具类

package com.project.common.util; import java.io.IOException; import java.io.InputStream; import java.util.Properties; import java.util.logging.Logger; /** * 开发人员: 匠心1990 * 日期:2016年8月18日 创建 * 功能

匠心1990 739

Java读取Properties配置文件工具类

Java读取Properties配置文件工具类 Java读取Properties配置文件 import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.*; import java.util.Properties; /** * 读取配置文件工具类 * @author hushuang */ publi...

大大的微笑的专栏 5654

Java读取properties配置文件工具类

Java读取properties配置文件的方式 一.背景 Java读取 properties 配置文件的方式,主要是通过 getProperty() 方法。config.properties 文件中有诸如 config.a = xxx 这样的存储形式,下面代码是读取 properties 配置文件中参数数据到 String 类型变量中。 二.代码 // 新建一个拥有 config.properti...

abcnull 的博客 2017

工具类:properties配置文件读取工具类

1 properties配置文件读取工具类 package com.wdy.tools.utils; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Properties; /** * Properties配置文件处理工具 * @author wdy */ public class PropertiesUtil { // 静态块中不能有非静态属性,所以加static

一天不写代码难受的博客 442

读取properties配置文件的工具类

一般小工程,properties配置文件之间在src根目录创建 比如data.properties,代码如下 [java] view plain copy  print?    PROXY=192.168.0.1      PORT=8080      USERNAME=username      PASSWORD=passwo

u014072347的专栏 489

java properties工具类_java读取properties配置文件工具类

Globals.properties文件#---------------ftp信息-------------ftpIP=192.168.1.156ftpPort=8831工具类package com.qfx.util;import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.InputStrea...

weixin_39943220的博客 170
上一篇: 日期及其格式化
下一篇: Eclipse中Web应用的开发
老李-大连
博客等级 码龄20年 3206粉丝 308原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值