BigDecimal 개체를 지수 형식을 사용하는 String 표현으로 변환하는 방법은 무엇입니까? 예 : 3.134e67
? API를 살펴본 결과 toEngineeringString()
이 발견되었지만 원하는 것을 제공하지 않습니다.BigDecimal을 지수 형식으로 변환하는 방법은 무엇입니까?
답변
당신이하는 NumberFormat 문서를 읽고,이 경우에 DecimalFormat에서입니다 : 참조 : http://docs.oracle.com/javase/1.4.2/docs/api/java/text/DecimalFormat.html
Scientific Notation
Numbers in scientific notation are expressed as the product of a mantissa and a power of ten, for example, 1234 can be expressed as 1.234 x 10^3. The mantissa is often in the range 1.0 <= x < 10.0, but it need not be. DecimalFormat can be instructed to format and parse scientific notation only via a pattern; there is currently no factory method that creates a scientific notation format. In a pattern, the exponent character immediately followed by one or more digit characters indicates scientific notation. Example: "0.###E0" formats the number 1234 as "1.234E3".
The number of digit characters after the exponent character gives the minimum exponent digit count. There is no maximum. Negative exponents are formatted using the localized minus sign, not the prefix and suffix from the pattern. This allows patterns such as "0.###E0 m/s".
The minimum and maximum number of integer digits are interpreted together:
If the maximum number of integer digits is greater than their minimum number and greater than 1, it forces the exponent to be a multiple of the maximum number of integer digits, and the minimum number of integer digits to be interpreted as 1. The most common use of this is to generate engineering notation, in which the exponent is a multiple of three, e.g., "##0.#####E0". Using this pattern, the number 12345 formats to "12.345E3", and 123456 formats to "123.456E3".
Otherwise, the minimum number of integer digits is achieved by adjusting the exponent. Example: 0.0formatted with "00.###E0" yields "12.3E-4".
The number of significant digits in the mantissa is the sum of the minimum integer and maximum fraction digits, and is unaffected by the maximum integer digits. For example, 12345 formatted with "##0.##E0" is "12.3E3". To show all digits, set the significant digits count to zero. The number of significant digits does not affect parsing.
Exponential patterns may not contain grouping separators.
이와 비슷한 제품을 찾고 계십니까?
YY^XX (모드 QQ)
int fastMod(int YY, int XX, int QQ){
int ZZ; //declare variables
int RR = 1;
while (XX != 0){ //while XX != 0
ZZ = XX % 2; //mod XX by 2
XX= XX/2; //divide XX by 2
if (ZZ == 1) //if ZZ is one
RR = (RR * YY) % QQ; //mod (RR*YY) by QQ
YY= (YY * YY) % QQ; //mod (YY*YY) by QQ
}
return RR; //return int
}
당신이 거대한 숫자를 사용하여 시작하면 당신은 모듈러 산술을 사용해야합니다. 이것은 RSA 알고리즘과 같이 큰 소수를 생성 할 때 특히 유용합니다. 모듈러 산술의 기본은 여기서 다루지 : http://www.brainjammer.com/math/modular-arithmetic/
나는 그것을 얻지 못한다. BigDecimal을 지수 형식으로 변환하는 데 어떻게 도움이 될까요? –
요점은 모듈러 산술을 사용하지 않으면 큰 숫자로 작업 할 수 없다는 것입니다. –
합니까이 도움 당신은?
BigDecimal bd = new BigDecimal(3.134e67);
String.valueOf(bd.doubleValue())
- 1. 지수 형식을 C의 십진수 형식으로 변환하는 방법
- 2. serialClob을 String 형식으로 변환하는 방법은 무엇입니까?
- 3. 문자열을 숫자 형식으로 변환하는 일반적인 방법은 무엇입니까?
- 4. 사람의 목소리를 디지털 형식으로 변환하는 방법은 무엇입니까?
- 5. JSON 개체를 날짜 형식으로 변환하는 방법은 무엇입니까?
- 6. xls 파일을 mysql 형식으로 변환하는 방법은 무엇입니까?
- 7. XML을 STEP (p21) 형식으로 변환하는 방법은 무엇입니까?
- 8. 난수를 다른 기본 형식으로 변환하는 방법은 무엇입니까?
- 9. java.hprof.txt를 바이너리 hprof 형식으로 변환하는 방법은 무엇입니까?
- 10. 보기의 내용을 이미지 형식으로 변환하는 방법은 무엇입니까?
- 11. ios5에서 NSString을 JSON 형식으로 변환하는 방법은 무엇입니까?
- 12. xml 파일을 html 형식으로 변환하는 방법은 무엇입니까?
- 13. 지수 형식을 PHP에서 실제 숫자로 변환하는 방법
- 14. XSLT에서 지수 형식을 숫자 형식으로 변환
- 15. BigDecimal을 문자열로 변환하여 검사합니다.
- 16. BigDecimal을 사용하여 통화로 작업하기
- 17. 음수를 2의 보수 바이너리 형식으로 변환하는 방법은 무엇입니까?
- 18. 아키텍처 형식으로 표시된 측정 값을 부동 소수점으로 변환하는 방법은 무엇입니까?
- 19. currentTimeMillis를 읽을 수있는 날짜 형식으로 변환하는 방법은 무엇입니까?
- 20. 클라이언트 측 GPX 및 KML을 JSON 형식으로 변환하는 방법은 무엇입니까?
- 21. Java에서 8 자 문자열을 ARGB 색상 형식으로 변환하는 방법은 무엇입니까?
- 22. 일반 텍스트 데이터를 관리되는 형식으로 변환하는 방법은 무엇입니까?
- 23. Apache Lucene : 컬렉션 인덱스를 다른 형식으로 변환하는 방법은 무엇입니까?
- 24. int를 itoa없이 C에서 이진 형식으로 변환하는 방법은 무엇입니까?
- 25. 이 형식을 Perl에서 JSON 형식으로 변환하는 방법은 무엇입니까?
- 26. iOS에서 CSV 또는 HTML 형식으로 데이터를 변환하는 방법은 무엇입니까?
- 27. After Effects에서 비디오를 Android 1.6 호환 형식으로 변환하는 방법은 무엇입니까?
- 28. xpath : 다음 xml을 결과 데이터 형식으로 변환하는 방법은 무엇입니까?
- 29. iOS에서 NSDictionary를 json 형식으로 올바르게 변환하는 방법은 무엇입니까?
- 30. T-SQL을 사용하여 테이블의 레코드를 xml 형식으로 변환하는 방법은 무엇입니까?
나는 이것을 시도했다 :'BigDecimal d = new BigDecimal ("55"); DecimalFormat df = 새로운 DecimalFormat ("0. ### E0"); System.out.println (df.format (d.toString()));',하지만 나에게 오류가 발생했습니다 : "주어진 객체를 숫자로 포맷 할 수 없습니다" –
이제 작동하고, 그냥 d.toString() 'd와 함께. 감사 :) –