编写一个程序,将用小数表示的浮点数,转换成科学计数法的形式输出

更新时间:2023-03-08 06:30:25 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

不知道你问什么语言

Java:浮点数输出,不显示成科学计数法

BigDecimal bg=new BigDecimal(\ System.out.println(bg.toPlainString()); C:

public abstract class ScienceCount {

public static string KXJSF(double num) {

double bef = System.Math.Abs(num); int aft = 0;

while (bef >= 10 || (bef < 1 && bef != 0)) {

if (bef >= 10)

{

bef=bef/10; aft++; } else {

bef=bef*10; aft--; } }

Return string.Concat(num >=0 ?\ }

///

/// 有效数字的处理 ///

/// /// 三位有效数字,不足则补零 public static string ReturnBef(double bef) {

if (bef.ToString() != null) {

char[] arr = bef.ToString().ToCharArray(); switch (arr.Length) {

case 1:

case 2: return string.Concat(arr[0], \

break;

case 3: return string.Concat(arr[0] + \

break;

default: return string.Concat(arr[0] + \ } } else {

return \ } }

///

/// 幂的处理 ///

///

/// 三位幂数部分,不足则补零 public static string ReturnAft(int aft) {

if (aft.ToString() != null) {

string end;

char[] arr = System.Math.Abs(aft).ToString().ToCharArray(); switch (arr.Length) {

case 1: end = \

break; case 2: end = \

break;

default: end = System.Math.Abs(aft).ToString();

break; }

return string.Concat(aft >=0 ?\ } else {

return \ }

}

}

//调用代码: static void Main() {

string num = \ while (num != \ {

num = Console.ReadLine();

if(!string.IsNullOrEmpty(num.Trim())) {

Console.WriteLine(ScienceCount.KXJSF(double.Parse(num))); }

} } }

本文来源:https://www.bwwdw.com/article/fme.html

Top