public class PercentUtil {
/**
* 百分比,保留2位有效数字 - 采用四舍五入方式
* @param numFirst
* @param numSecond
* @return
*/
public static String preciseDividion(String numFirst,String numSecond){
BigDecimal dividend = new BigDecimal(numFirst);
BigDecimal divisor = new BigDecimal(numSecond);
BigDecimal result = dividend.divide(divisor, 4,BigDecimal.ROUND_HALF_UP);
//加上%后相当于扩大100倍
return result.movePointRight(2).toString();
}
/**
* 占比计算保留小数的位数方法
* 转成百分数
* 当前数除以总数
* @param num1 ,num2 num1/num2
* @return rate 保留2位小数的
*/
public static String division(int num1,int num2){
String rate="0.00%";
//定义格式化起始位数
String format="0.00";
if(num2 != 0 && num1 != 0){
DecimalFormat dec = new DecimalFormat(format);
rate = dec.format((double) num1 / num2*100)+"%";
while(true){
if(rate.equals(format+"%")){
format=format+"0";
DecimalFormat dec1 = new DecimalFormat(format);
rate = dec1.format((double) num1 / num2*100)+"%";
}else {
break;
}
}
}else if(num1 != 0 && num2 == 0){
rate = "100%";
}
return rate;
}
/**
* 把上面得到的百分比转为字符串类型的小数 保留两位小数
* @author shw
*/
public static BigDecimal perToDecimal(String percent){
String decimal = percent.substring(0,percent.indexOf("%"));
BigDecimal bigDecimal = new BigDecimal(decimal);
bigDecimal.divide(new BigDecimal("100"), 4, BigDecimal.ROUND_HALF_UP);
return bigDecimal;
}
}
相关推荐
【Matlab 六自由度机器人】基于改进型D-H参数的运动学建模与蒙特卡洛工作空间分析
本文详细介绍了如何使用改进型D-H参数法为六自由度机器人建立运动学模型,并利用Matlab Robotics Toolbox实现正运动学计算与可视化。通过蒙特卡洛法对机器人工作空间进行分析,生成三维点云图以直观展示其可达范围,为机器人选型与任务规划提供关键依据。
BigDecimal比较大小的时候,比较结果与实际不符的情况
https://blog.csdn.net/qq_33451004/article/details/71247041 比较大小的时候最好不要使用new BigDecimal(xx)来比较,而应该使用BigDecimal.valueOf(xx); 原因是new BigDecimal(double)是利用的double构造方法,该构造方法有一定的不可预料性; 比如比较一个值是否等于100...
单细胞测序数据读取实战指南:从入门到精通
本文提供了单细胞测序数据读取的实战指南,涵盖从标准10X Genomics格式到通用表达矩阵及RDS文件的读取方法。文章重点解析了数据读取的核心步骤、常见问题解决方案及进阶技巧,旨在帮助用户夯实数据分析基础,确保后续分析流程的准确性。
BigDecimal 比较大小
BigDecimal所创建的是对象,我们不能使用传统的+、-、*、/等算术运算符直接对对象进行数学运算,而必须调用其相对应的方法。方法中的参数也必须是BigDecimal的对象。比较大小用compareTo()方法,大于为1,小于为-1,等于为0。首先创建BigDecimal对象。BigDecimal 比较大小。
移植 lwip,在 windows 内核构建一个 TCPIP 协议栈
移植 lwip,在 windows 内核构建一个 TCPIP 协议栈 亲,当你点开看这篇文章,就说明你知道我想要干什么事情,或者说,你知道在 Windows 的内核种绕开它的网络协议,再独立构建一个网络协议栈的意义。如果你要问我有 windows 系统的网络协议栈不用,移植 lwip 有什么意义,那么你可以关闭链接走人了,因为这篇文章不适合你,它不是讲 lwip 移植原理的。 经常关注我的博客的朋...
基于zynq在linux下的AXI-CAN实战
从petalinux的搭建,到uboot、kernel、rootfs的调试、打包提示:以下是本篇文章正文内容,下面案例可供参考本次要讲述的zynq的AXI-CAN实战小知识就说到这里了,兄弟萌要有什么指导意见或疑问可以在评论区留下"足迹"。
BigDecimal 判断大于小于
BigDecimal 判断大于小于
基于YOLO+DeepSeek的农作物病虫害检测系统
本系统是一个基于YOLO+DeepSeek的农作物病虫害检测系统。 可使用YOLOV1-YOLOV12的任意模型进行目标检测。可以实现检测图片、批量检测图片、视频检测、摄像头检测四种方式。
BigDecimal加减乘除及比较大小
import java.math.BigDecimal; import static java.lang.System.out; public class BaseClass { public static void main(String[] args) { BigDecimal num1 = new BigDecimal("100"); BigDec...
【飞控】UAV Toolbox Support Package for PX4 Autopilots安装与配置
安装配置UAV Toolbox Support Package for PX4 Autopilots硬件安装包
别再乱点U盘里的.exe了!手把手教你清除‘Usb Disk.exe’病毒并恢复隐藏文件
本文详细介绍了如何识别和清除U盘病毒(如Usb Disk.exe),并提供从终止病毒进程到恢复隐藏文件的完整步骤。通过禁用自动播放、清理注册表和使用命令行工具,帮助用户彻底清除病毒并预防未来感染,确保数据安全。
BigDecimal 浅析
BigDecimal
【芯片设计- RTL 数字逻辑设计入门 番外篇6 -- 术语 Tile 介绍】
在系统级芯片(System on Chip, SoC)设计中,“tile” 是一个可以指代不同概念的术语,但通常它指的是芯片上的一个独立的功能单元或核心。一个 tile 可以包含一个或多个处理器核心、缓存、内存控制器、输入输出设备、外设接口或其他功能模块。在 SoC 上,多个 tile 可以被组合和连接起来,以形成一个完整的系统。
DecimalFormat基本用法
1.保留两位小数(截断) double num = 11.255; DecimalFormat df = new DecimalFormat("#.##"); //指定RoundingMode df.setRoundingMode(RoundingMode.DOWN); String str = df.format(num); double formatNum = Double.parseDouble(str);
深度学习工具包 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');```[](https://bitdeli.com/free "Bitdeli Badge")
efm32 入门.pdf
本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。
DecimalFormat详解、关于DecimalFormat的取舍问题,DecimalFormat四舍五入的坑
背景 在使用DecimalFormat对数字进行格式化的时候,发现数字有时候四舍五入了,有时候又没有四舍五入,针对这个问题进行研究。 测试代码 public static void main (String[] args) { DecimalFormat df=new DecimalFormat("#.#"); double a=3.25,b=3.35; System.out.println(df.format(a)); System.out.
复分析 阿尔福斯(Ahlfors) 第三版答案 英文
答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案
关于DecimalFormat的使用
在easyexcel的jar包中, 有两个注解 Numbermat和DateTimeFormat.1 Numbermat注解中引用自DecimalFormat类.DecimalFormat类是jdk中java.text.包下的一个具体子类, 用于格式化十进制数字. 其抽象父类是NumberFormat, 其作用于格式化和解析任何区域设置的数字, 继承于公共父类Format.2 DateTimeFormat注解引用自SimpleDateFormat类。
IEM模型,地表粗糙度模拟
利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟
DecimalFormat 的用法
DecimalFormat 是 NumberFormat 的一个具体子类,用于格式化十进制数字。DecimalFormat 包含一个模式 和一组符号,在做数字格式化时,DecimalFormat还是比较方便的。常用于保留小数点后几位、数字间用,分割、四舍五入等场合。 关键符号: 0:只要有可能就把数字拉上这个位置,不包括 0 .: 小数的分隔符的占位符 -:缺省负数前缀。 ,:分组分...
BigDecimal和DecimalFormat
文章目录前言一、BigDecimal1.1 概述1.2 常用构造函数1.3 常用方法1.4 BigDecimal比较大小二、DecimalFormat注意 前言 在些银行或商城项目业务中,需要数据的精度要求较高,而在Java中基本数据类型‘float’或者‘double’这些代表浮点型的数据类型在进行数据运输时结果并不会和我们预期的一致,因为其运算可能会发生精度丢失。 在这样引用一个比较经典的案例:为什么会出现4.0-3.6=0.3999999999这种现象? double a = 4.0; do
DecimalFormat类
DecimalFormat类: DecimalFormat是NumberFormat十进制数字格式的具体子类 。它具有多种功能,旨在解析和格式化任何语言环境中的数字,包括支持西方,阿拉伯语和印度语数字。它还支持不同类型的数字,包括整数(123),定点数(123.4),科学记数法(1.23E4),百分比(12%)和货币金额(123美元)。而且对于数值的小数部分,默认显示3位小数,在去掉超出小数点后...
DecimalFormat的使用
前言 原来没有接触过DecimalFormat,没有想到还有这玩意。使用的时候还是不错的,详细的了解可以看官方的api。找到了中文的api,小伙子们可以直接跳转啊! DecimalFormat 是 NumberFormat 的一个具体子类,用于格式化十进制数字。 DecimalFormat 包含一个模式 和一组符号。差点忘记说它是干嘛的。 符号含义: 上一个经典的表格,我们来说一说响应的符号的意义...
java的decimalFormat_Java中DecimalFormat用法详解
我们经常要将数字进行格式化,比如取2位小数,这是最常见的。Java 提供DecimalFormat类,帮你用最快的速度将数字格式化为你需要的样子。下面是一个例子:importjava.text.DecimalFormat;public class TestNumberFormat{public static void main(String[]args){doublepi=3.1415927; /...
DecimalFormat(取舍问题,DecimalFormat四舍五入的坑)
舍入方式
decimalformat精度丢失_DecimalFormat
DecimalFormat是格式为十进制数的NumberFormat的具体子类。它具有各种功能,旨在使任何地区的数字解析和格式化,包括支持西方,阿拉伯语和印度数字。它还支持不同类型的数字,包括整数(123),定点数(123.4),科学记数法(1.23E4),百分比(12%)和货币金额(123美元)。所有这些都可以进行本地化。要获取特定区域设置的NumberFormat (包括默认语言环境),请致电...
DecimalFormat详解
如下: /** * 将double值转为显示格式 * * @param f * @return */ public static String toDoubleView(double f) { BigDecimal b = new BigDecimal(f); f = b.setScale(
DecimalFormat简单使用
介绍 DecimalFormat 是 NumberFormat 的一个具体子类,用于格式化十进制数字。 在做数字格式化时,DecimalFormat还是比较方便的。常用于保留小数点后几位、数字间用,分割、四舍五入等场合。 关键符号 0:只要有可能就把数字拉上这个位置,不包括 0 .: 小数的分隔符的占位符 ,:分组分隔符的占位符 (只能放在整数部分) - :缺省负数前缀。 %: 乘以...
关于Java中DecimalFormat()方法的调用
关于Java中DecimalFormat()方法的调用 我们可以从各种地方知道DecimalFormat类的使用方法,它的作用是格式化数字。 在此不多赘述,博主现在是一个本科生也处于初学Java阶段,这里就讲一下关于DecimalFormat类的构造方法的发现与探索。 我分别建立了两个方法,一个用有参方法实例化对象,另一个用无参方法实例化对象。 public class Decimal...
443



被折叠的 条评论
为什么被折叠?



