本文介绍了如何在Java中将区域设置格式的数字转换为BigInteger?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了很多,但没有帮助我:(假设我需要将12.090.129.019.201.920.192.091.029.102.901.920.192.019.201.920(在葡萄牙语组分隔符:。)转换为BigInteger值。如何转换?我尝试使用NumberFormat,DecimalFormat和没有任何工作,或者我没有正确的方式:(

解决方案

获取,然后解析这个数字,这也将处理特定于locale的小数点分隔符。

  NumberFormat nf = NumberFormat.getNumberInstance(new Locale(pt,PT)); 
DecimalFormat df =(DecimalFormat)nf;
df.setParseBigDecimal(true);
BigDecimal decimal =(BigDecimal)df.parse(12.090.129.019.201.920.192.091.029.102.901.9 20.192.019.201.920\" );
BigInteger big = decimal.toBigInteger();


I searched a lot but nothing helped me :( Suppose I need convert 12.090.129.019.201.920.192.091.029.102.901.920.192.019.201.920 (in Portuguese group separator: .) to BigInteger value. How to do that conversion? I tried use NumberFormat, DecimalFormat and nothing works or I didn't on right way :(

解决方案

Get a NumberFormat instance for a Portuguese Locale, and then parse the number with it. This will also handle locale-specific decimal separators.

NumberFormat nf = NumberFormat.getNumberInstance(new Locale("pt", "PT"));
DecimalFormat df = (DecimalFormat)nf;
df.setParseBigDecimal(true);
BigDecimal decimal = (BigDecimal)df.parse("12.090.129.019.201.920.192.091.029.102.901.920.192.019.201.920");
BigInteger big = decimal.toBigInteger();

DEMO.

这篇关于如何在Java中将区域设置格式的数字转换为BigInteger?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 01:46