C#在小数点中移动小数点 [英] C# move decimal point in a double
问题描述
我想将格式为xx.xxxx的滑块转换为双倍格式为xxxxxx.xx的双倍格式。
示例如果收到:15.678934我想把它传入:156789.34
我在几个地方检查过但我只找到要在之前或之后舍入或添加ceros的公式
mydouble.ToString( ######。##,CultureInfo.InvariantCulture));
mydouble.ToString( 0000:00.00, CultureInfo.InvariantCulture));
我还检查了starndart和自定义字符串格式,但显然没有任何东西适合我的目标:http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs .110).aspx [ ^ ]
请帮忙吗?
试试这个:
double d = 12 。< span class =code-digit> 345678 ;
Console.WriteLine( {0,8:000000.00},d);
Console.WriteLine( {0},d.ToString( 000000.00));
我不知道我在想什么!最近我不得不做很多解析和转换的东西,我没有意识到,对于这种情况,解决方案是简单的数学!!
double dconverted = mydouble * 10000;
d.tostring( ######。##);
I want to transform a double get it from a slider with format "xx.xxxx" into a double with next format "xxxxxx.xx".
Example if receive: 15.678934 I want to convet it in: 156789.34
I checked in several places but I only find formulas to round or add ceros before or after like
mydouble.ToString("######.##", CultureInfo.InvariantCulture) );
mydouble.ToString("0000:00.00", CultureInfo.InvariantCulture) );
Also I checked the starndart and custom string formats but apparently nothing fits with my objetive: http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx[^]
Any help please ?
Try this:
double d = 12.345678; Console.WriteLine("{0,8:000000.00}", d); Console.WriteLine("{0}", d.ToString("000000.00"));
I don't know what I was thinking ! Lately I had to do many parsing and conversions stuff that I didn't realize that for this case the solution were simple maths!!
double dconverted=mydouble*10000; d.tostring("######.##");
这篇关于C#在小数点中移动小数点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!