返回首页

gbase数据、南大通用产品文档:GBase8srfmtdouble() 函数

更新日期:2024年09月11日

rfmtdouble() 函数使用格式化掩码来将 double 值转换为字符串。

语法
mint rfmtdouble(dbl_val, fmtstring, outbuf)
double dbl_val;
char *fmtstring;
char *outbuf;
dbl_val
要格式化的 double 数值。
fmtstring
指向包含 dbl_val 中的值的格式化掩码的字符缓冲区的指针。

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 870 -

outbuf
指向接收 dbl_val 中的值的格式化的字符串的字符缓冲区的指针。

用法
rfmtdouble() 函数的 fmtstring 参数指向数值格式化掩码,其包含描述
如何格式化 double 值的字符。

当您使用 rfmtdouble() 来格式化 MONEY 值时,该函数使用 DBMONEY 环境变量
指定的货币符号。如果您未指定此环境变量,则 rfmtdouble() 使用客户机语言环境定义的
货币符号。
缺省的语言环境 US English 定义货币符号如同您将 DBMONEY 设置为
“$,.”
一样。

当您使用有多字节代码集的非缺省的语言环境时,rfmtdouble() 支持格式字符串中的
多字节字符。

返回代码
0
转换成功。
-1211
程序用尽内存(内存分配错误)。
-1217
格式字符串太大。

示例
demo 目录在文件 rfmtdouble.ec 中包含此样例程序。
/*
* rfmtdouble.ec *
The following program applies a series of format specifications to series of doubles
and displays the result of each format.
*/

#include



GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 871 -

double dbls[] =
{
210203.204,
4894,
443.334899312,
-12344455,
0
};

char *formats[] =
{
"#############",
"<,<<<,<<<,<<<",
"$$$$$$$$$$.##",
"(&&,&&&,&&&.)",
"$*********.**",
0
};

char result[41];

main()
{
mint x;
mint i = 0, f;

printf("RFMTDOUBLE Sample ESQL Program running.\n\n");

while(dbls[i]) /* for each number in dbls */
{
printf("Double Number = %g\n", dbls[i]);
f = 0;
while(formats[f]) /* format with each of formats[] */

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 872 -

{
if (x = rfmtdouble(dbls[i], formats[f], result))
{
printf("Error %d in formatting %g using %s\n",
x, dbls[i], formats[f]);
break;
}
/*
* Display each result and bump to next format (f++)
*/
result[40] = '\0';
printf(" Format String = '%s'\t", formats[f++]);
printf("\tResult = '%s'\n", result);
}
++i; /* bump to next double */
printf("\n"); /* separate result groups */
}
printf("\nRFMTDOUBLE Sample Program over.\n\n");
}
输出
RFMTDOUBLE Sample ESQL Program running.

Double Number = 210203
Format String = '#############'
Result = ' 210203'
Format String = '<,<<<,<<<,<<<'
Result = '210,203'
Format String = '$$$$$$$$$$.##'
Result = ' $210203.20'
Format String = '(&&,&&&,&&&.)'
Result = ' 000210,203. '
Format String = '$*********.**'
Result = '$***210203.20'

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 873 -


Double Number = 4894
Format String = '#############'
Result = ' 4894'
Format String = '<,<<<,<<<,<<<'
Result = '4,894'
Format String = '$$$$$$$$$$.##'
Result = ' $4894.00'
Format String = '(&&,&&&,&&&.)'
Result = ' 000004,894. '
Format String = '$*********.**'
Result = '$*****4894.00'

Double Number = 443.335
Format String = '#############'
Result = ' 443'
Format String = '<,<<<,<<<,<<<'
Result = '443'
Format String = '$$$$$$$$$$.##'
Result = ' $443.33'
Format String = '(&&,&&&,&&&.)'
Result = ' 0000000443. '
Format String = '$*********.**'
Result = '$******443.33'

Double Number = -1.23445e+07
Format String = '#############'
Result = ' 12344455'
Format String = '<,<<<,<<<,<<<'
Result = '12,344,455'
Format String = '$$$$$$$$$$.##'
Result = ' $12344455.00'
Format String = '(&&,&&&,&&&.)'

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 874 -

Result = '(12,344,455.)'
Format String = '$*********.**'
Result = '$*12344455.00'

RFMTDOUBLE Sample Program over.

所有“信息模式”视图都会将 Select 特权授予 PUBLIC WITH GRANT OPTION,以便所
有用户都可查询这些视图。因为未对“信息模式”视图授予任何其他特权,所以不能更新
它们。
可以如同查询数据库中的任何其他表或视图那样查询“信息模式”视图。

Client SDK 允许您开发和运行客户机应用程序。
下表描述了 Client SDK 的组件。
表 1. Client SDK 组件
组件
描述
GBase
8s
ESQL/C
(带 XA
支持)
SQL 语言嵌入产品,用于创建定制 C 应用程序。
有关更多信息,请参阅《GBase 8s ESQL/C 程序员手册》。
GBase 8s Object
Interface for C++
用来开发面向对象的客户机应用程序的 C++ 接口,
这些应用程序
可与所有 GBase 8s 数据库服务器和 GBase 8s 客户机端值对象
配合使用。
GBase 8s GLS (Global
Language Support)
允许 GBase 8s 产品使用不同语言环境的接口,这些语言环境定
义了特定语言、文化或代码集的约定。
有关更多信息,
请参阅
《GBase
8s
ESQL/C 程序员手册》

《GBase
8s GLS 用户指南》。
GBase 8s ODBC Driver
(带 MTS 支持)
Open
Database
Connectivity
(ODBC)