| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2455 人关注过本帖
标题:关于浮点转字符串的问题求教大虾
只看楼主 加入收藏
love_me
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2005-12-29
收藏
 问题点数:0 回复次数:5 
关于浮点转字符串的问题求教大虾


把第一个框和第二个框的内容相加输出到第三个框

在MFC中我可以这样:
CString x;
CString y;
double m,n,o;
CString str;
void CZIFUDlg::OnBnClickedOk()
{

GetDlgItemText(IDC_EDIT1,x);
GetDlgItemText(IDC_EDIT2,y);
m=atof(x);
n=atof(y);
o=m+n;

str.Format ("%.2f",o);
SetDlgItemText(IDC_EDIT3,str);

// TODO: 在此添加控件通知处理程序代码
//OnOK();
}
在C#中可以这样:
double x;
x=Convert.ToDouble(this.TextBox1.Text)+Convert.ToDouble(this.TextBox2.Text);

this.TextBox3.Text=x.ToString();


在WIN32中,因为没有CString 和STR.Format()函数而遇到问题~求救解决办法,不胜感激~

搜索更多相关主题的帖子: 大虾 字符 str IDC CString 
2005-12-29 21:26
love_me
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2005-12-29
收藏
得分:0 

我原来学C#的,现在发现用C#编的程序要使人家使用还要强迫人家安装.NET ,太烦人,所以改学C++,求救~~~~~~~~~~


灌水无罪! 顶贴有理! <0_0>
2005-12-29 21:30
love_me
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2005-12-29
收藏
得分:0 

后来学MFC,现在发现用MFC编的程序要使人家使用还要强迫给人家一个MFC71D.dll,太烦人,所以改学win32,求救~~~~~~~~~~


灌水无罪! 顶贴有理! <0_0>
2005-12-30 10:51
柳儿
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:1830
专家分:30
注 册:2004-9-23
收藏
得分:0 

有String类可以用吧?

[此贴子已经被作者于2005-12-30 13:27:29编辑过]


成功会使人骄傲。如果你骄傲自大,你就会停止学习。不学习,人就停止了进步
2005-12-30 13:23
RL720
Rank: 1
等 级:新手上路
帖 子:148
专家分:0
注 册:2005-11-6
收藏
得分:0 
用fcvt
_fcvt
Converts a floating-point number to a string.

char *_fcvt( double value, int count, int *dec, int *sign );

Function Required Header Compatibility
_fcvt <stdlib.h> Win 95, Win NT


For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version


Return Value

_fcvt returns a pointer to the string of digits. There is no error return.

Parameters

value

Number to be converted

count

Number of digits after decimal point

dec

Pointer to stored decimal-point position

sign

Pointer to stored sign indicator

Remarks

The _fcvt function converts a floating-point number to a null-terminated character string. The value parameter is the floating-point number to be converted. _fcvt stores the digits of value as a string and appends a null character ('\0'). The count parameter specifies the number of digits to be stored after the decimal point. Excess digits are rounded off to count places. If there are fewer than count digits of precision, the string is padded with zeros.

Only digits are stored in the string. The position of the decimal point and the sign of value can be obtained from dec and sign after the call. The dec parameter points to an integer value; this integer value gives the position of the decimal point with respect to the beginning of the string. A zero or negative integer value indicates that the decimal point lies to the left of the first digit. The parameter sign points to an integer indicating the sign of value. The integer is set to 0 if value is positive and is set to a nonzero number if value is negative.

_ecvt and _fcvt use a single statically allocated buffer for the conversion. Each call to one of these routines destroys the results of the previous call.

Example

/* FCVT.C: This program converts the constant
* 3.1415926535 to a string and sets the pointer
* *buffer to point to that string.
*/

#include <stdlib.h>
#include <stdio.h>

void main( void )
{
int decimal, sign;
char *buffer;
double source = 3.1415926535;

buffer = _fcvt( source, 7, &decimal, &sign );
printf( "source: %2.10f buffer: '%s' decimal: %d sign: %d\n",
source, buffer, decimal, sign );
}


Output

source: 3.1415926535 buffer: '31415927' decimal: 1 sign: 0

[此贴子已经被作者于2005-12-31 0:28:38编辑过]


2005-12-31 00:28
love_me
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2005-12-29
收藏
得分:0 
char *_fcvt( double value, int count, int *dec, int *sign );


你这里的COUNT是保留了7位吧,如果我想把PI=3.14159265....保留无限位,那该怎么办?

有时候我不知道一个数除以另外一个数有多少位小数,这个时候我就要保留我够长位,我的精度要够高的话,该怎么办?

还有就是INT *DEC 跟INT *SIGN是什么意思?有什么用?

我在WIN32中发现没有%f,只有%d,%c,%s真叫人郁闷~而在命令行里是有的~

该如何在win32里输出诸如命令行的%f 呢?

灌水无罪! 顶贴有理! <0_0>
2006-01-03 17:27
快速回复:关于浮点转字符串的问题求教大虾
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015275 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved