搜档网
当前位置:搜档网 › ULHGA operator and its application to group decision making under uncertain linguistic envi

ULHGA operator and its application to group decision making under uncertain linguistic envi

ULHGA operator and its application to group decision making under uncertain linguistic envi
ULHGA operator and its application to group decision making under uncertain linguistic envi

ULHGA operator and its application to group decision

making under uncertain linguistic environment

Wei Guiwu a,b

a

School of Economics and Management, Southwest Jiaotong University, Chengdu,

China (610031)

b

Department of Mathematics, North Sichuan Medical College, Nanchong, China (637007)

Abstract

In this paper, we study multiple attribute group decision making problem with uncertain linguistic information, in which the attribute weights and expert weights take the form of real numbers, and the preference values take the form of uncertain linguistic variables. An uncertain linguistic aggregation operator called uncertain linguistic hybrid geometric aggregation (ULHGA) operator is proposed. An approach to multiple attribute group decision making (MAGDM) with uncertain linguistic information is developed based on the ULWGM and the ULHGA operators. Finally, an illustrative example is given to verify the developed approach and to demonstrate its practicality and effectiveness. Keywords: ULHGA operator; group decision making; uncertain linguistic variables

1. Introduction

Making decisions with linguistic information is a usual task faced by many decision makers [1], and thus, the use of a linguistic approach is necessary [2]. Many approaches have been proposed for aggregating information up to now [1-6]. Particularly for the uncertain linguistic MAGDM problems, in which the attribute weights and expert weights take the form of real numbers, and the preference values take the form of uncertain linguistic variables, an approach based on the ULOWA and ULHA operators is proposed [4]; an approach based on the IULOWA and ULWA operators is proposed [5]; an approach based on the ULOWG and IULOWG operators is proposed [6]

. For the same decision problem, in this paper, we shall develop an uncertain linguistic aggregation operator called uncertain linguistic hybrid geometric aggregation (ULHGA) operator. Based on the ULWGM and the ULHGA operators, we shall develop an approach to MAGDM under uncertain linguistic environment. Finally, the method has been demonstrated by a practical example.

2. Operational Laws of Linguistic Variables [1,4,5,6]

Let {}

1,2,,i S s i t ==L be a linguistic term set with odd cardinality. Any label,i s represents a possible value for a linguistic variable, and it should satisfy the following characteristics:①The set is ordered:i j s s >,if i j >;②There is the negation operator: ()i j neg s s = such that

1i j t +=+;③Max operator:()max ,i j i s s s =, if i j s s ≥;④Min operator: ()min ,i j i s s s =, if i j s s ≤;.For example, S can be defined as

1234567{,,,,

,,}

S s extremely poor s very poor s poor s medium s good s very good s extremely good ========

To preserve all the given information, we extend the discrete term set S to a continuous term set {}

1,[1,]a a q S s s s s a q =≤≤∈, where q is a sufficiently large positive integer. If a s S ∈, then we call a s the original linguistic term, otherwise, we call a s the virtual linguistic term. In

general, the decision maker uses the original linguistic term to evaluate attributes and alternatives, and the virtual linguistic terms can only appear in calculation.

Let [,]s s s αβ=%, where ,s s S αβ∈,s α and s β are the lower and the upper limits,

respectively, we the call s

% the uncertain linguistic variable. Let S % be the set of all the uncertain linguistic variables.

Consider any three uncertain linguistic variables ,s s s αβ??=??%,111,s s s αβ??=??% and

222,s s s αβ??=??%,[]12,,,0,1s

s s S λ∈∈%%%% , we define their operational laws as follows: (1) 11221212121212,,,,s s s s s s s s s s s s αβαβααββααββ++????????⊕=⊕=⊕⊕=????????%%; (2) 11221212121212,,,,s s s s s s s s s s s s αβαβααββααββ?????????=?=??=????????%%;

(3) ()()

()(),,,s s s s s s s λλλ

λλ

λαβαβαβ??????===??

????

??%. Definition 1. Let 111,s s s αβ??=??% and 222,s

s s αβ??=??% be two uncertain linguistic variables, and let ()111len s βα=?%,()222len s βα=?%, then the degree of possibility of 12s s ≥%% is defined as ()()()()()()()12211212max 0,max ,0len s

len s p s

s len s

len s βα+??≥=+%%%%%% (1)

From Definition 1,we can easily get the following results easily:

(1) ()()122101,01p s

s p s s ≤≥≤≤≥≤%%%%; (2) ()()12211p s

s p s s ≥+≥=%%%%. Especially, ()()11220.5p s s p s s ≥=≥=%%%%. 3. ULHGA Operator

Some operators are introduced or proposed as follows:

Definition 2. Let :n

ULWGM S

S →%%, if

()()()()121212ULWGM ,,,n n n s s s s s s ωωω

ω=???%%%%%%L L (2)

where ()12,,,n ωωωω=L is the exponential weighting vector of uncertain linguistic variables

()

,1,2,,i i s s S i n ∈=%%%L with []0,1i

ω∈,11n

i

i ω

==∑, then function ULWGM is called the

uncertain linguistic weighted geometric (ULWGM) operator of dimension n [6].

Example 1. Assume ()0.2,0.3,0.4,0.1T

ω=, []112,s s s =%, []214,s s s =%,[]335,s s s =%, and []424,s

s s =%, then ()[][][][][]0.2

0.30.40.1

123412143524 1.66 3.81ULW GM ,,,,,,,,s

s s s s s s s s s s s s s ω=???=%%%%

Definition 3. Let (),1,2,,i i i a b s s s i n ??==??%L be a uncertain linguistic terms sets, and

()()()

()1

21212ULOWG ,,,n w w w

w n n s s s r r r =???%%%%%%L L (3)

where ()12,,,n w w w w =L is the associated exponential weighting vector, with []0,1j w ∈,

1

1n

j

j w

==∑,and j r % is the j-th largest element in the uncertain linguistic variables set

()12,,,n s

s s %%%L , then the function ULOWGA is called the uncertain linguistic ordered weighted geometric (ULOWG) operator of dimension n [6].

From Definition 2 and 3, we know that the ULWGM operator weights the uncertain linguistic arguments while the ULOWG operator weights the ordered positions of the uncertain linguistic argument instead of weighting the arguments themselves. Therefore, weights represent different aspects in both the ULWGM and ULOWG operators. However, both the operators consider only one of them. To solve this drawback, in the following we shall propose an uncertain linguistic hybrid geometric aggregation (ULHGA) operator.

Definition 4. Let (),1,2,,i i i a b s s s i n ??==??%L be a uncertain linguistic terms sets, and

()()()

()1

2,1212ULHGA ,,,n w w w

w n n s s s r r r ω=???%%%%%%L L (6) where ()12,,,n w w w w =L is the associated exponential weighting vector, with []0,1j w ∈,

1

1n

j

j w

==∑,and j r % is the j-th largest element of the uncertain linguistic weighted argument

()()i

n i i i s

s s ω′′=%%%,()1

2

,,,n

ωωωω=L is the exponential weighting vector of uncertain linguistic

variables ()1,2,,i s

i n =%L ,with []0,1i ω∈,11n

i

i ω

==∑, and n is the balancing coefficient, then

the function ULHGA is called the uncertain linguistic hybrid geometric aggregation (ULHGA)

operator of dimension n.

Example 2. Assume ()0.2,0.3,0.4,0.1T

ω=,()0.2,0.3,0.3,0.2T

w =, and

[]125,s

s s =%, []234,s s s =%,[]312,s s s =%, []424,s s s =% By Definition 4, we have

[][]40.2

125 1.74 3.62,,s s s s s ×′==%,[][]40.3

234 3.74 5.28,,s

s s s s ×′==% [][]40.4

312 1.00 3.03,,s

s s s s ×′==%,[][]40.1

424 1.32 1.74,,s

s s s s ×′==%

To rank these arguments, we first compare each argument i s

′% with all arguments ()1,2,3,4j s

j ′=% by using Eq. (1), and let ()ij i j p p s s ′′=≥%%. Then we construct a complementary matrix:

0.5000.0000.670 1.0001.0000.500 1.000 1.0000.3300.0000.5000.6980.000

0.0000.302

0.500P ??

???

?=??

?

???

Summing all elements in each line of matrix P , we get:

12342.17, 3.50, 1.53,0.80p p p p ====

Then we can rank the arguments ()1,2,3,4i s

i ′=% in descending order in accordance with the values of ()1,2,3,4i p i =.

[][]12 1.00 5.2821 1.74 3.62,,,r s s s r s s s ′′====%%%%,[][]33 1.00 3.0344 1.32 1.74,,,r s s s r s s s ′′====%%%%

Thus,

()[][][][]

[]

0.20.3

w,1234 1.00 5.28 1.74 3.620.3

0.2

1.00 3.03 1.32 1.74 1.62 3.20ULHGA ,,,,,,,,s

s s s s s s s s s s s s s ω=???=%%%%

Theorem 1 .The ULWM operator is a special case of the ULHGA operator. Proof. Let ()1,1,,1w n n n =L , then

()()()

()()()()()()()1

212,12121111112ULHGA ,,,n

n

w w

w w n n n n n n s s s r r r s

s s s

s s ωωωω=???′′′=???=???%%%%%%L L %%%%%%L L

which completes the proof of Theorem 1.

Theorem 2 .The ULOWG operator is a special case of the ULHGA operator.

Proof. Let ()1,1,,1n n n ω=L , then i i s

s ′=%%,1,2,,i n =L . This completes the proof of Theorem 2.

From Theorem 1 and 2, we know that the ULHGA operator generalizes both the ULWGM and ULOWG operators, and reflects the importance degrees of both the given arguments and their ordered positions.

4. An Approach to Group Decision Making under Uncertain Linguistic Environment

For the group decision making problems, in which both the attribute weights and the expert weights take the form of real numbers, and the attribute preference values take the form of uncertain linguistic variables, we shall develop an approach based on the ULWGM and ULHGA operators to group decision making under uncertain linguistic environment as follows.

Let {}12,,,m A A A A =L be a discrete set of alternatives, {}12,,,n G G G G =L be the set of attributes, ()12,,,n ωωωω=L is the exponential weighting vector of the attributes

()1,2,,j G j n =L , where []0,1j ω∈,1

1n

j j ω==∑,{}12,,,t D D D D =L be the set of decision

makers, and ()12,,,n νννν=L be the weighting vector of decision makers, where with

[]0,1k ν∈, 1

1t

k k ν==∑. Suppose that ()()

k k

ij m n

R r ×=%% is the decision matrix, where ()

k ij r

S ∈%% is a preference value, in which take the form of uncertain linguistic variable, given by the decision maker k D D ∈, for the alternative i A A ∈ with respect to the attribute j G G ∈.

Step 1. Utilize the decision information given in matrix k

R %,and the ULWGM operator ()()()()

()

12,,,,1,2,,,1,2,,.k k k k i i i in r ULWGM r r r i m k t ω===%%%%L L L

to derive the individual overall preference value ()

k i r

% of the alternative i A .

Step 2. Utilize the ULHGA operator:

()()()()

12,,,,,1,2,,t i w i i i r

ULHGA r r r i m ν==%%%%L L to derive the collective overall preference values ()1,2,,i r

i m =%L of the alternative i A ,where ()12,,,n νννν=L be the weighting vector of decision makers, with []0,1k ν∈, 1

1t

k k ν==∑;

()12,,,n w w w w =L is the associated exponential weighting vector of the ULHGA operator,

with []0,1j w ∈,

1

1n

j

j w

==∑.

Step 3. To rank these collective overall preference values ()1,2,,i r

i m =%L , we first compare each i r

% with all the ()1,2,,j r j m =%L by using Eq. (1) . For simplicity, we let ()

ij i j p p r r =≥%%, then we develop a complementary matrix as ()

ij

m m

P p ×=, where 0ij p ≥, 1ij ji p p +=,

0.5ii p =, ,1,2,,i j n =L [1,4,5,6].

Summing all the elements in each line of matrix P , we have [1,4,5,6]

1

,1,2,,m

i ij j p p i m ===∑L .

Then we rank the collective overall preference values ()1,2,,i r

i m =%L in descending order in accordance with the values of ()1,2,,i p i m =L .

Step 4. Rank all the alternatives ()1,2,,i A i m =L and select the best one(s) in accordance with

the collective overall preference values ()1,2,,i r

i m =%L . Step 5. End.

5. Illustrative Example

Let us suppose there is an investment company, which wants to invest a sum of money in the

best option (adapted from [2]). There is a panel with five possible alternatives to invest the money:①A 1 is a car company;②A 2 is a food company;③A 3 is a computer company;④A 4 is a arms company;⑤A 5 is a TV company. The investment company must take a decision according to the following four attributes:G ①1 is the risk analysis;G ②2 is the growth analysis;G ③3 is the social-political impact analysis;G ④4 is the environmental impact analysis. The five possible alternatives ()1,2,,5i A i =L are to be evaluated using the linguistic term set.

1234567{,,,,

,,}

S s extremely poor s very poor s poor s medium s good s very good s extremely good ========

By the three decision makers (whose weighting vector ()0.3,0.4,0.3T

ν=) under the above four attributes, and construct, respectively, the decision matrices as listed in the following matrices

()()

()54

1,2,3k k ij

R r k ×==%% :

1

2341233412122124534231324

134537445122323534461434[,][,][,][,][,][,][,][,][,][,][,][,][,][,][,][,][,]

[,][,][,]G G G G A s s s s s s s s A s s s s s s s s R A s s s s s s s s A s s s s s s s s A s s s s s s s s ???

?

????=?

?

??

????%

1234

1121412372132423232324

121226423343513512451313[,]

[,]

[,][,][,][,][,][,][,][,][,][,][,][,][,][,][,][,]

[,]

[,]G G G G A s s s s s s s s A s s s s s s s s R A s s s s s s s s A s s s s s s s s A s s s s s s s s ????????

=????????

% 1

2

3

4

1241512122122412243326

351413424134724535242556[,]

[,][,][,][,][,][,][,][,][,][,][,][,][,][,][,][,]

[,][,][,]G G G G A s s s s s s s s A s s s s s s s s R A s s s s s s s s A s s s s s s s s A s s s s s s s s ??

?

?

??

??

=?

?

??????

%

In the following, we shall utilize the proposed approach in this paper to get the most desirable

alternative(s):

Step 1. Utilize the decision information given in matrix k

R %, and the ULWGM operator (Let ()0.3,0.1,0.2,0.4T

ω=) :

()()()()

()

12,,,,1,2,3,4,5,1,2,3k k k k i i i in r ULWGM r r r i k ω===%%%%L

to derive the individual overall preference value ()

k i r

% of the alternative i A .

()[]()[]()[]()[]()

[]111111 1.37 2.422 1.89 2.963 2.52 5.084 2.30 3.365 2.48 4.17,,,,,,,,,r s s r s s r s s r s s r s s =====%%%%%()[]()[]()[]()[]()[]222221

1.55 3.542 1.62 3.093 1.62 3.824 1.71 3.425 1.15

2.80,,,,,,,,,r s s r s s r s s r s s r s s =====%%%%%()[]()[]()[]()[]()[]333331

1.23

2.702 1.41 2.833 1.37 4.124 2.14 4.355

3.26 5.26,,,,,,,,,r s s r s s r s s r s s r s s =====%%%%% Step 2. Utilize the ULHGA operator:

()()()()

123,,,,1,2,3,4,5i w i i i r

ULHGA r r r i ν==%%%% to derive the collective overall preference values ()1,2,,i r

i m =%L of the alternative i A ,where ()0.3,0.4,0.3T

ν= be the weighting vector of decision makers, ()0.4,0.3,0.3w =is the

associated exponential weighting vector of the ULHGA operator.

[][][][][]1 1.42 3.042 1.65 3.053 1.77 4.334 1.99 3.725 2.05 3.87,,,,,,,,,r s s r s s r

s s r s s r s s =====%%%%% Step 3. Rank these collective overall preference values ()1,2,3,4,5i r

i =%, we first compare each i r

% with all the ()1,2,3,4,5j r j =% by using Eq. (1), and then develop a complementary matrix: 0.500

0.4620.3060.3140.2880.5380.5000.3240.3380.3090.694

0.6760.5000.5440.5190.6860.6620.4560.5000.4700.7120.6910.4810.5300.500P ??

???

???=?

?

??????

Summing all the elements in each line of matrix P , we have

123451.871, 2.008, 2.934, 2.774, 2.914.p p p p p =====

Then we rank the collective overall preference values ()1,2,3,4,5i r

i =% in descending order in accordance with the values of ()1,2,,5i p i =L : 35421r r r r r %%%%%f f f f .

Step 4. Rank all the alternatives ()1,2,,5i A i =L in accordance with the overall preference

values ()1,2,3,4,5i r

i =%:35421A A A A A f f f f , and thus the most desirable alternative is 3A .

6. Conclusion

In this paper, we have developed an uncertain linguistic hybrid geometric aggregation

(ULHGA) operator. We have proved both ULWM and ULOWG operators are the special case of the ULHGA operator. The ULHGA operator generalizes both the ULWGM and ULOWG operators, and reflects the importance degrees of both the given arguments and their ordered positions. Based on the ULWM and ULHGA operators, we have proposed an approach to MAGDM under uncertain linguistic environment. We have also applied the proposed approach to the practical problem.

References

[1] Xu, Z S. Uncertain multiple attribute decision making: methods and applications[M]. Tsinghua University Press, Beijing,2004. (in Chinese )

[2] Delgado, M, Herrera F, Herrera-Viedma E , Martinez L. Combining numerical and linguistic information in group decision making[J]. Information Sciences, 1998,107:177–194.

[3] Degani R , Bortolan G . The problem of linguistic approximation in clinical decision making[J]. International Journal of Approximate Reasoning,1998,12(2):143-162..

[4] Xu Z S. Uncertain linguistic aggregation operators based approach to multiple attribute group decision making under uncertain linguistic environment[J].Information Science,2004,168:171-184.

[5] Xu Z S. Induced uncertain linguistic OWA operators applied to group decision making[J]. Information fusion, 2004,41:488-499.

[6] Xu Z S. An approach based on the uncertain LOWG and induced uncertain LOWG operators to group decision making with uncertain multiplicative linguistic preference relations[J]. Decision Support Systems, 2006,41:488-499.

常用数据类型转换使用详解

VC常用数据类型使用转换详解 CString ,BSTR ,LPCTSTR之间关系和区别 CString是一个动态TCHAR数组,BSTR是一种专有格式的字符串(需要用系统提供的函数来操纵,LPCTSTR只是一个常量的TCHAR指针。 CString 是一个完全独立的类,动态的TCHAR数组,封装了 + 等操作符和字符串操作方法。typedef OLECHAR FAR* BSTR; typedef const char * LPCTSTR; vc++中各种字符串的表示法 首先char* 是指向ANSI字符数组的指针,其中每个字符占据8位(有效数据是除掉最高位的其他7位),这里保持了与传统的C,C++的兼容。 LP的含义是长指针(long pointer)。LPSTR是一个指向以‘/0’结尾的ANSI字符数组的指针,与char*可以互换使用,在win32中较多地使用LPSTR。 而LPCSTR中增加的‘C’的含义是“CONSTANT”(常量),表明这种数据类型的实例不能被使用它的API函数改变,除此之外,它与LPSTR是等同的。 1.LP表示长指针,在win16下有长指针(LP)和短指针(P)的区别,而在win32下是没有区别的,都是32位.所以这里的LP和P是等价的. 2.C表示const 3.T是什么东西呢,我们知道TCHAR在采用Unicode方式编译时是wchar_t,在普通时编译成char. 为了满足程序代码国际化的需要,业界推出了Unicode标准,它提供了一种简单和一致的表达字符串的方法,所有字符中的字节都是16位的值,其数量也可以满足差不多世界上所有书面语言字符的编码需求,开发程序时使用Unicode(类型为wchar_t)是一种被鼓励的做法。 LPWSTR与LPCWSTR由此产生,它们的含义类似于LPSTR与LPCSTR,只是字符数据是16位的wchar_t而不是char。 然后为了实现两种编码的通用,提出了TCHAR的定义: 如果定义_UNICODE,声明如下: typedef wchar_t TCHAR; 如果没有定义_UNICODE,则声明如下: typedef char TCHAR; LPTSTR和LPCTSTR中的含义就是每个字符是这样的TCHAR。 CString类中的字符就是被声明为TCHAR类型的,它提供了一个封装好的类供用户方便地使用。

matlab数据类型及转换

Matlab中有15种基本数据类型,主要是整型、浮点、逻辑、字符、日期和时间、结构数组、单元格数组以及函数句柄等。 1、整型:(int8;uint8;int16;uint16;int32;uint32;int64;uint64)通过intmax(class)和intmin(class) 函数返回该类整型的最大值和最小值,例如intmax(‘int8’)=127; 2、浮点:(single;double) 浮点数:REALMAX('double')和REALMAX('single')分别返回双精度浮点和单精度浮点的最大值,REALMIN('double')和REALMIN ('single')分别返回双精度浮点和单精度浮点的最小值。 3、逻辑:(logical) Logical:下例是逻辑索引在矩阵操作中的应用,将5*5矩阵中大于0.5的元素设定为0: A = rand(5); A(A>0.5)=0; 4、字符:(char) Matlab中的输入字符需使用单引号。字符串存储为字符数组,每个元素占用一个ASCII字符。如日期字符:DateString=’9/16/2001’ 实际上是一个1行9列向量。构成矩阵或向量的行字符串长度必须相同。可以使用char函数构建字符数组,使用strcat函数连接字符。 例如,命令name = ['abc' ; 'abcd'] 将触发错误警告,因为两个字符串的长度不等,此时可以通过空字符凑齐如:name = ['abc ' ; 'abcd'],更简单的办法是使用char函数:char(‘abc’,’abcd’),Matlab自动填充空字符以使长度相等,因此字符串矩阵的列纬总是等于最长字符串的字符数. 例如size(char(‘abc’,’abcd’))返回结果[2,4],即字符串’abc’实际存在的是’abc ’,此时如需提取矩阵中的某一字符元素,需要使用deblank函数移除空格如name =char(‘abc’,’abcd’); deblank(name(1,:))。 此外,Matlab同时提供一种更灵活的单元格数组方法,使用函数cellstr可以将字符串数组转换为单元格数组: data= char(‘abc’,’abcd’) length(data(1,:)) ->? 4 cdata=cellstr(data) length(cdata{1}) ->?3 常用的字符操作函数 blanks(n) 返回n个空字符 deblank(s) 移除字符串尾部包含的空字符 (string) 将字符串作为命令执行 findstr(s1,s2) 搜索字符串 ischar(s) 判断是否字符串 isletter(s) 判断是否字母 lower(s) 转换小写 upper(s) 转换大写 strcmp(s1,s2) 比较字符串是否相同 strncmp(s1,s2,n) 比较字符串中的前n个字符是否相同 strrep(s1,s2,s3) 将s1中的字符s2替换为s3 5、日期和时间 Matlab提供三种日期格式:日期字符串如’1996-10-02’,日期序列数如729300(0000年1月1日为1)以及日期向量如1996 10 2 0 0 0,依次为年月日时分秒。 常用的日期操作函数

2.3 基本数据类型的转换

2.3基本数据类型的转换 本章目标 掌握基本数据类型间的自动转换 掌握任何基本数据类型的数据都会自动向String转换 掌握基本数据类型间的强制转换 Java的数据类型在定义时就已经确定了,因此不能随意转换成其他的数据类型,但Java允许用户有限度地做类型转换处理。数据类型的转换方式可分为“自动类型转换”及“强制类型转换”两种。 1 数据类型的自动转换 在计算机中完成一个计算时,要求参与计算的两个数值必须类型一致,如果不一致,计算机会自动将其中一个数值类型转换成另外一个数值的类型,然后完成计算。自动转换的原则如下: (1)转换前的数据类型与转换后的类型兼容。 (2)转换后的数据类型的表示范围比转换前的类型大。 例如,将short类型的变量a转换为int类型,由于short与int皆为整数类型,符合上述条件(1);而int的表示范围比short大,符合条件(2)。因此Java 会自动将原为short类型的变量a转换为int类型。 要注意的是,类型的转换只限该行语句,并不会影响原先所定义的变量的类型,而且通过自动类型的转换可以保证数据的精确度,它不会因为转换而损失数据内容。这种类型的转换方式也称为扩大转换。 范例:数据类型的转换 程序运行结果: x / y = 1.3519603 10 / 3.5 = 2.857142857142857 10 / 3 = 3 从程序的输出结果可以发现,int类型与float类型进行计算之后,输出的结

果会变成float类型,一个整型常量和一个浮点型常量进行计算之后,结果也会变为一个浮点数据,而如果两个int类型的常量进行计算,最终结果还是int类型,而其小数部分将会被忽略。 也就是说,假设有一个整数和双精度浮点数据做运算时,Java会所整数转换成双精度浮点数后再做运算,运算结果也会变成双精度浮点数。 提示:任何类型的数据都向String转型。 有一种表示字符串的数据类型String,从其定义上可以发现单词首字母大写了,所以此为一个类,属于引用数据类型,但是此类属于系统类,而且使用上有些注意事项,对于此种类型后面会有介绍,在此处所需要知道的只有以下两点: (1)String可以像普通变量那样直接通过赋值的方式进行声明。字符串是使用“””括起来的。两个字符串之间可以使用“+”进行连接。 (2)任何数据类型碰到String类型的变量或常量之后都向String类型转换。 范例:定义字符串变量 程序运行结果: str = lixinghua30 从运行结果来看,可以发现整型数据30自动转换成了字符的“30”,与字符串“lixinghua”进行了连接操作,变成了一个新的字符串“lixinghua30”。 范例:字符串常量操作的问题

java的基本数据类型有八种

java的基本数据类型有八种 各位读友大家好!你有你的木棉,我有我的文章,为了你的木棉,应读我的文章!若为比翼双飞鸟,定是人间有情人!若读此篇优秀文,必成天上比翼鸟! java的基本数据类型有八种四类八种基本数据类型1. 整型byte(1字节)short (2个字节)int(4个字节)long (8个字节)2.浮点型float(4个字节)double(8个字节)3.逻辑性boolean(八分之一个字节)4.字符型char(2个字节,一个字符能存储下一个中文汉字)基本数据类型与包装类对应关系和默认值short Short (short)0int Integer 0long Long 0Lchar Char '\u0000'(什么都没有)float Floa t0.0fdouble Double 0.0dboolean Boolean false 若某个类的某个成员是基本数据类型,即使没有初始化,java也会确保它获得一个默认值,如上所示。(这种初始化方法只是用于成员变量,不适用于局部变量)。jdk1.5支持自动拆装箱。可以将基本数据类型转换成它的包装类装箱Integer a = new Integer ();a = 100;拆箱int b = new Intger(100);一个字节等于8位,一个字节等于256个数,-128到127一个英文字母或一个阿拉伯数字就是一个字符,占用一个字节一个汉字两个字符,占用两个字节基本数据类型自动转换byte->short , char->int->longfloat->doubleint ->floatlong->double小可转大,大转小会失去精度。字符串与基本类型或其他类型间的转换⑴其它

数据类型转换

数据类型转换 一、隐式类型转换 1)简单数据类型 (1)算术运算 转换为最宽的数据类型 eg: [cpp] view plain copy #include using std::cout; using std::endl; int main(int argc, char* argv[]) { int ival = 3; double dval = 3.14159; cout << ival + dval << endl;//ival被提升为double类型 return 0; } 其运行结果: 6.14159 int main(int argc, char* argv[]) { 010D17D0 push ebp 010D17D1 mov ebp,esp 010D17D3 sub esp,0DCh 010D17D9 push ebx 010D17DA push esi 010D17DB push edi 010D17DC lea edi,[ebp-0DCh] 010D17E2 mov ecx,37h 010D17E7 mov eax,0CCCCCCCCh 010D17EC rep stos dword ptr es:[edi] int ival = 3; 010D17EE mov dword ptr [ival],3 double dval = 3.14159; 010D17F5 movsd xmm0,mmword ptr [__real@400921f9f01b866e (010D6B30h)]

010D17FD movsd mmword ptr [dval],xmm0 cout << ival + dval << endl;//ival被提升为double类型 010D1802 mov esi,esp 010D1804 push offset std::endl > (010D1064h) 010D1809 cvtsi2sd xmm0,dword ptr [ival] 010D180E addsd xmm0,mmword ptr [dval] 010D1813 mov edi,esp 010D1815 sub esp,8 010D1818 movsd mmword ptr [esp],xmm0 010D181D mov ecx,dword ptr [_imp_?cout@std@@3V?$basic_ostream@DU?$char_traits@D@std@@@1@A (010D90A8h)] 010D1823 call dword ptr [__imp_std::basic_ostream >::operator<< (010D90A0h)] 010D1829 cmp edi,esp 010D182B call __RTC_CheckEsp (010D111Dh) 010D1830 mov ecx,eax 010D1832 call dword ptr [__imp_std::basic_ostream >::operator<< (010D90A4h)] 010D1838 cmp esi,esp 010D183A call __RTC_CheckEsp (010D111Dh) return 0; 010D183F xor eax,eax } 010D1841 pop edi } 010D1842 pop esi 010D1843 pop ebx 010D1844 add esp,0DCh 010D184A cmp ebp,esp 010D184C call __RTC_CheckEsp (010D111Dh) 010D1851 mov esp,ebp 010D1853 pop ebp 010D1854 ret (2)赋值 转换为被赋值对象的类型,但不会改变赋值对象的数据类型。 eg: [cpp] view plain copy #include

C++基本数据类型转换

atof(将字符串转换成浮点型数) 相关函数 atoi,atol,strtod,strtol,strtoul 表头文件 #include 定义函数 doubleatof(const char *nptr); 函数说明 atof()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时('\0')才结束转换,并将结果返回。参数nptr字符串可包含正负号、小数点或E(e)来表示指数部分,如123.456或123e-2。 返回值 返回转换后的浮点型数。 附加说明 atof()与使用strtod(nptr,(char**)NULL)结果相同。 范例 /* 将字符串a 与字符串b转换成数字后相加*/ #include main() { char *a=”-100.23”; char *b=”200e-2”; float c; c=atof(a)+atof(b); printf(“c=%.2f\n”,c); } 执行 c=-98.23 atoi(将字符串转换成整型数) 相关函数 atof,atol,atrtod,strtol,strtoul 表头文件 #include

定义函数 intatoi(const char *nptr); 函数说明 atoi()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时('\0')才结束转换,并将结果返回。 返回值 返回转换后的整型数。 附加说明 atoi()与使用strtol(nptr,(char**)NULL,10);结果相同。 范例 /* 将字符串a 与字符串b转换成数字后相加*/ #include mian() { char a*+=”-100”; ch ar b*+=”456”; int c; c=atoi(a)+atoi(b); printf(c=%d\n”,c); } 执行 c=356 atol(将字符串转换成长整型数) 相关函数 atof,atoi,strtod,strtol,strtoul 表头文件 #include 定义函数 longatol(const char *nptr); 函数说明 atol()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时('\0')才结束转换,并将结果返回。 返回值 返回转换后的长整型数。 附加说明 atol()与使用strtol(nptr,(char**)NULL,10);结果相同。 范例

数据类型转换

数据类型转换 各类整数之间的转换 C语言中的数分8位、16位和32位三种。属于8 位数的有:带符号 字符char,无符号字符unsigned char 。属于16位数的有:带符号整 数int,无符号整数unsigned int(或简写为unsigned),近指针。属 于32位数的有:带符号长整数long,无符号长整数 unsigned long, 远指针。 IBM PC是16位机,基本运算是16位的运算,所以,当8位数和16 位数进行比较或其它运算时,都是首先把8 位数转换成16位数。为了 便于按2的补码法则进行运算,有符号8位数在转换为16位时是在左边 添加8个符号位,无符号8位数则是在左边添加8个0。当由16位转换成 8位时,无论什么情况一律只是简单地裁取低8位,抛掉高8 位。没有 char或usigned char常数。字符常数,像"C",是转换为int以后存储 的。当字符转换为其它 16 位数(如近指针)时,是首先把字符转换为 int,然后再进行转换。 16位数与32位数之间的转换也遵守同样的规则。 注意,Turbo C中的输入/输出函数对其参数中的int和unsigned int不加区分。例如,在printf函数中如果格式说明是%d 则对这两种 类型的参数一律按2 的补码(即按有符号数)进行解释,然后以十进制 形式输出。如果格式说明是%u、%o、%x、%X,则对这两种类型的参数 一律按二进制 (即按无符号数) 进行解释,然后以相应形式输出。在 scanf函数中,仅当输入的字符串中含有负号时,才按2的补码对输入 数进行解释。 还应注意,对于常数,如果不加L,则Turbo C一般按int型处理。 例如,语句printf("%081x",-1L),则会输出ffffffff。如果省略1, 则输出常数的低字,即ffff。如果省略L,则仍会去找1个双字,这个 双字的就是int常数-1,高字内容是不确定的,输出效果将是在4个乱 七八糟的字符之后再跟ffff。 在Turbo C的头文件value.h中,相应于3 个带符号数的最大值, 定义了3个符号常数: #define MAXSHORT 0X7FFF #define MAXINT 0X7FFF #define MAXLONG 0X7FFFFFFFL 在Turbo C Tools中,包括3对宏,分别把8位拆成高4位和低4位, 把16位拆成高8位和低8位,把32位拆成高16位和低16位。 uthinyb(char value) utlonyb(char value) uthibyte(int value) utlobyte(int value) uthiword(long value) utloword(long valueu) 在Turbo C Tools中,也包括相反的3 个宏,它们把两个4位组成 一个8位,把两个8位组成一个16位,把两个16位组成一个32位。 utnybbyt(HiNyb,LoNyb) utwdlong(HiWord,Loword) utbyword(HiByte,LoByte)实数与整数之间的转换 Turbo C中提供了两种实数:float和 double。float 由32 位组 成,由高到低依次是:1个尾数符号位,8个偏码表示的指数位(偏值= 127),23个尾数位。double由64位组成,由高到低依次是:1 个尾数

Java语言基本数据类型、转换及其封装

Java语言基本数据类型、转换及其封装Java语言基本数据类型、转换及其封装 1. 逻辑类型 ·常量 true,false。 ·变量的定义 使用关键字boolean来定义逻辑变量: boolean x; boolean tom_12; 也可以一次定义几个: boolean x,tom,jiafei,漂亮 x,tom,jiafei,漂亮都是变量的名字。定义时也可以赋给初值: boolean x=true,tom=false,漂亮=true,jiafei 2.整数类型 ·常量123,6000(十进制),077(八进制),0x3ABC(十六进制)。 ·整型变量的定义分为4种: 1.int 型 使用关键字int来定义int型整形变量 int x int tom_12 也可以定义几个: int x,tom,jiafei,漂亮 x,tom,jiafei,漂亮都是名字。定义时也可以赋给初值: int x=12,tom=-1230,漂亮=9898,jiafei 对于int型变量,分配给4个字节byte,一个字节由8位(bit)组成,4个字节占32位(bit)。bit 有两状态,分别用来表示0,1。这样计算机就可以使用2进制数来存储信息了。内存是一种特殊的电子元件,如果把内存条放大到摩天大

楼那么大,那么它的基本单位——字节,就好比是大楼的房间,每个房间的结构都是完全相同的,一个字节由8个能显示两种状态的bit组成,就好比每个房间里有8个灯泡,每个灯泡有两种状态——亮灯灭灯。 对于 int x=7; 内存存储状态如下: 00000000 00000000 00000000 00000111 最高位:左边的第一位,是符号位,用来区分正数或负数,正数使用原码表示,最高位是0,负数用补码表示,最高位是1。例如: int x=-8; 内存的存储状态如下: 11111111 11111111 11111111 11111000 要得到-8的补码,首先得到7的原码,然后将7的原码中的0变成1,1变成0,就是-8的补码。 因此,int型变量的取值范围是-2^31~2^31-1。 2. byte型 使用关键字byte来定义byte型整型变量 byte x ; byte tom_12; 也可以一次定义几个: byte x,tom,jiafei,漂亮 x,tom,jiafei,漂亮都是名字。定义时也可以赋给初值: byte x=-12,tom=28,漂亮=98,jiafei 注:对于byte型变量,内存分配给1个字节,占8位,因此byte型变量的取值范围是: -2^7~2^7-1。

基本数据类型

首先为什么要有数据类型? 数据类型的出现是为了把数据分成所需内存大小不同的数据,编程的时候需要用大数据的时候才需要申请大内存,就可以充分利用内存。例如大胖子必须睡双人床,就给他双人床,瘦的人单人床就够了。 Java中的基本类型从概念上分为四种:整数、浮点、字符、布尔值。总共有八种,其列表如下: 名词解释: 字节(Byte)是:计算机文件大小的基本计算单位。 1个字节(Byte) = 8个位(Bit) Bit意为“位”或“比特”,是计算机运算的基础;二进制中的一位,是二进制最小信息单位.二进位可以用来表示一个简单的正/负的判断,有两种状态的开关(如电灯开关) . 简单换算结果:

1个字节(Byte) = 8个位(Bit) 2个字节(Byte) = 16个位(Bit) 4个字节(Byte) = 32个位(Bit) 8个字节(Byte) = 64个位(Bit) 在内存计算过程中,字节少的数据运算速度更快;在硬盘存储中,字节少的数据类型也可充分存入更多的数据。 Java的基本数据类型讲解如下: int:int为整数类型,在存储的时候,用4个字节存储,范围为-2,147,483,648到2,147,483,647,在变量初始化的时候,int 类型的默认值为0。 short:short也属于整数类型,在存储的时候,用2个字节存储,范围为-32,768到32,767,在变量初始化的时候,short类型的默认值为0,一般情况下,因为Java本身转型的原因,可以直接写为0。 long:long也属于整数类型,在存储的时候,用8个字节存储,范围为-9,223,372,036,854,775,808到9,223,372,036, 854,775,807,在变量初始化的时候,long类型的默认值为0L或0l,也可直接写为0。 byte:byte同样属于整数类型,在存储的时候,用1个字节来存储,范围为-128到127,在变量初始化的时候,byte类型的默认值也为0。 float:float属于浮点类型,在存储的时候,用4个字节来存储,范围为32位IEEEE 754单精度范围,在变量初始化的时候,float

JAVA中常用数据类型之间转换的方法

Java中常用数据类型之间转换的方法 Java中几种常用的数据类型之间转换方法: 1.short-->int转换 exp:short shortvar=0; int intvar=0; shortvar=(short)intvar 2.int-->short转换 exp:short shortvar=0; int intvar=0; intvar=shortvar; 3.int->String转换 exp:int intvar=1; String stringvar; Stringvar=string.valueOf(intvar); 4.float->String转换 exp:float floatvar=9.99f; String stringvar;

Stringvar=String.valueOf(floatvar); 5.double->String转换 exp double doublevar=99999999.99; String stringvar; Stringvar=String.valueOf(doublevar); 6.char->String转换 exp char charvar=’a’; String stringvar; Stringvar=String.valueOf(charvar); 7String->int、float、long、double转换Exp String intstring=”10”; String floatstring=”10.1f”; String longstring=”99999999”; String doubleString=”99999999.9”; Int I=Integer.parseInt(intstring); Float f=Integer.parseInt(floatstring); Long lo=long.parseInt(longstring); Double d=double.parseInt(doublestring); 8String->byte、short转换

基本数据类型与数值表达式

基本数据类型与数值表达式 一、知识要点 计算机的基本功能是进行数据处理。在C++语言中,数据处理的基本对象是常量和变量。运算是对各种形式的数据进行处理。数据在内存中存放的情况由数据类型所决定。数据的操作要通过运算符实现,而数据和运算符共同组成了表达式。本章是对C++语言中的数据类型、运算符、表达式等内容的全面介绍,要正确理解其特点,并灵活运用,主要掌握以下的知识要点: 1.掌握常量和变量的概念。 2.掌握整型数据和实型数据、字符型数据和字符串型数据的概念和区别。 3.掌握各种类型的变量说明及其初始化。 4.掌握算术运算、关系运算、逻辑运算、赋值运算、逗号运算、条件运算等概念。 5.掌握运算符的优先级、左结合和右结合规则。 6.掌握表达式求值时的自动转换和强制类型转换。 7.掌握自加、自减运算的规则。 8.掌握常用数学函数的功能。 二、例题分析与解答 1.选择题 例题1:运算符+、=、*、>=中,优先级最高的运算符是()。 A.+ B.= C.* D.>= 答案:C 分析:根据C++语言对运算符优先级的规则,以上运算符优先级从低到高的次序为=、>=、+、*。 例题2:下列说法正确的是()。 A.cout<<”\n”是一个语句,它能在屏幕上显示”\n” B.\68代表的是字符D。

C.1E+5的写法正确,它表示余割整型常量。 D.0x10相当于020。 答案:D 分析:分号是语句的已部分,且\n是转义字符;\68代表了八进制的6、8,而八进制中没有数字8;1E+5是实型常量;十六进制的10相当于十进制的16,相当于八进制的20。 例题3:下列不合法的变量名为()。 A.int B.int1 C.name_1 D.name0 答案:A 分析:根据变量名命名要求,变量名只能由大小写字母、数字、下划线组成,且系统关键字不能作为变量名。 例题4:下面正确的为()。 A.4.1/2 B.3.2%3 C.3/2==1 结果为1 D.7/2 结果为3.5 答案:A 分析:%运算符要求式整型;关系运算值为0;两个整数相除,商为为相除后的整数部分。 例题5:已知a=4,b=6,c=8,d=9,则“(a++,b>a++&&c>d)?++d:a

java基本数据类型之间的转换.

java 基本数据类型之间的转换 - fishinhouse的专栏 - CSDNBlog fishinhouse的专栏做一件事,最难的是开始,最重要的是坚持。如果坚持,就会达到目的! 登录注册全站当前博客空间博客好友相册留言wl ID:fishinhouse java 基本数据类型之间的转换收藏新一篇: 常用log4j配置 | 旧一篇: java代码编写的30条建议我们知道,Java的数据类型分为三大类,即布尔型、字符型和数值型,而其中数值型又分为整型和浮点型;相对于数据类型,Java的变量类型为布尔型boolean;字符型char;整型byte、short、int、long;浮点型float、double。其中四种整型变量和两种浮点型变量分别对应于不同的精度和范围。此外,我们还经常用到两种类变量,即String和Date。对于这些变量类型之间的相互转换在我们编程中经常要用到,在下面的论述中,我们将阐述如何实现这些转换。 1 数据类型转换的种类 java数据类型的转换一般分三种,分别是: (1. 简单数据类型之间的转换 (2. 字符串与其它数据类型的转换 (3. 其它实用数据类型转换下面我们对这三种类型转换分别进行论述。 2 简单数据类型之间的转换在Java中整型、实型、字符型被视为简单数据类型,这些类型由低级到高级分别为(byte,short,char--int--long--float--double 简单数据类型之间的转换又可以分为:●低级到高级的自动类型转换●高级到低级的强制类型转换●包装类过渡类型能够转换 2.1自动类型转换低级变量可以直接转换为高级变量,笔者称之为自动类型转换,例如,下面的语句可以在Java中直接通过:byte b; int i=b; long l=b; float f=b; double d=b; 如果低级类型为char型,向高级类型(整型)转换时,会转换为对应ASCII码值,例如r char c='c'; int i=c; System.out.println("output:" i; 输出:output:99; 对于byte,short,char三种类型而言,他们是平级的,因此不能相互自动转换,可以使用下述的强制类型转换。 short i=99;char c=(chari;System.out.println("output:" c; 输出:output:c; 但根据笔者的经验,byte,short,int三种类型都是整型,因此如果操作整型数据时,最好统一使用int 型。 2.2强制类型转换将高级变量转换为低级变量时,情况会复杂一些,你可以使用强制类型转换。即你必须采用下面这种语句格式: int i=99;byte b=(bytei;char c=(chari;float f=(floati; 可以想象,这种转换肯定可能会导致溢出或精度的下降,因此笔者并不推荐使用这种转换。 2.3包装类过渡类型转换在我们讨论其它变量类型之间的相互转换时,我们需要了解一下Java的包装类,所谓包装类,就是

matlab数据类型和转换

matlab数据类型和转换 Matlab中有15种基本数据类型,主要是整型、浮点、逻辑、字符、日期和时间、结构数组、单元格数组以及函数句柄等。 1、整型:(int8;uint8;int16;uint16;int32;uint32;int64;uint64)通过intmax(class)和intmin(class) 函数返回该类整型的最大值和最小值,例如intmax(‘int8’)=127; 2、浮点:(single;double) 浮点数:REALMAX('double')和REALMAX('single')分别返回双精度浮点和单精度浮点的最大值,REALMIN('double')和REALMIN ('single')分别返回双精度浮点和单精度浮点的最小值。 3、逻辑:(logical) Logical:下例是逻辑索引在矩阵操作中的应用,将5*5矩阵中大于0.5的元素设定为0: A = rand(5); A(A>0.5)=0; 4、字符:(char) Matlab中的输入字符需使用单引号。字符串存储为字符数组,每个元素占用一个ASCII字符。如日期字符:Date String=’9/16/2001’ 实际上是一个1行9列向量。构成矩阵或向量的行字符串长度必须相同。可以使用char函数构建字符数组,使用strcat函数连接字符。 例如,命令 name = ['abc' ; 'abcd'] 将触发错误警告,因为两个字符串的长度不等,此时可以通过空字符凑齐如:name = ['abc ' ; 'abcd'],更简单的办法是使用char函数:char(‘abc’,’abcd’),Matlab自动填充空字符以使长度相等,因此字符串矩阵的列纬总是等于最长字符串的字符数. 例如s ize(char(‘abc’,’abcd’))返回结果[2,4],即字符串’abc’实际存在的是’abc ’,此时如需提取矩阵中的某一字符元素,需要使用deblank 函数移除空格如name =char(‘abc’,’abcd’); deblank(name(1,:))。 此外,Matlab同时提供一种更灵活的单元格数组方法,使用函数cellstr 可以将字符串数组转换为单元格数组: data= char(‘abc’,’abcd’) length(data(1,:)) ->? 4 cdata=cellstr(data) length(cdata{1}) ->?3 常用的字符操作函数 blanks(n) 返回n个空字符 deblank(s) 移除字符串尾部包含的空字符 (string) 将字符串作为命令执行 findstr(s1,s2) 搜索字符串 ischar(s) 判断是否字符串 isletter(s) 判断是否字母 lower(s) 转换小写 upper(s) 转换大写 strcmp(s1,s2) 比较字符串是否相同

常用数据类型使用转换详解

常用数据类型使用转换详解 刚接触VC编程的朋友往往对许多数据类型的转换感到迷惑不解,本文将介绍一些常用数据类型的使用。 我们先定义一些常见类型变量借以说明 int i = 100; long l = 2001; float f=300.2; double d=12345.119; char username[]="程佩君"; char temp[200]; char *buf; CString str; _variant_t v1; _bstr_t v2; 一、其它数据类型转换为字符串 短整型(int) itoa(i,temp,10);///将i转换为字符串放入temp中,最后一 个数字表示十进制 itoa(i,temp,2); ///按二进制方式转换 长整型(long) ltoa(l,temp,10); 浮点数(float,double) 用fcvt可以完成转换,这是MSDN中的例子: int decimal, sign; char *buffer; double source = 3.1415926535;

buffer = _fcvt( source, 7, &decimal, &sign ); 运行结果:source: 3.1415926535 buffer: '31415927' decimal: 1 sign: 0 decimal表示小数点的位置,sign表示符号:0为正数,1为负数 CString变量 str = "2008北京奥运"; buf = (LPSTR)(LPCTSTR)str; BSTR变量 BSTR bstrValue = ::SysAllocString(L"程序员"); char * buf = _com_util::ConvertBSTRToString(bstrValue); SysFreeString(bstrValue); AfxMessageBox(buf); delete(buf); CComBSTR变量 CComBSTR bstrVar("test"); char *buf = _com_util::ConvertBSTRToString(bstrVar.m_str); AfxMessageBox(buf); delete(buf); _bstr_t变量 _bstr_t类型是对BSTR的封装,因为已经重载了=操作符,所以很容易使用 _bstr_t bstrVar("test"); const char *buf = bstrVar;///不要修改buf中的内容AfxMessageBox(buf); 通用方法(针对非COM数据类型)

常见的类型转换

常用数据类型使用转换详解 先定义一些常见类型变量借以说明 int i = 100; long l = 2001; float f=300.2; double d=12345.119; char username[]="女侠程佩君"; char temp[200]; char *buf; CString str; _variant_t v1; _bstr_t v2; 一、其它数据类型转换为字符串 短整型(int) itoa(i,temp,10); //将i转换为字符串放入temp中,最后一个数字表示十进制itoa(i,temp,2); //按二进制方式转换 长整型(long) ltoa(l,temp,10);

二、从其它包含字符串的变量中获取指向该字符串的指针CString变量 str = "2008北京奥运"; buf = (LPSTR)(LPCTSTR)str; BSTR类型的_variant_t变量 v1 = (_bstr_t)"程序员"; buf = _com_util::ConvertBSTRToString((_bstr_t)v1); 三、字符串转换为其它数据类型 strcpy(temp,"123"); 短整型(int) i = atoi(temp); 长整型(long) l = atol(temp); 浮点(double) d = atof(temp); 四、其它数据类型转换到CString 使用CString的成员函数Format来转换,例如:

整数(int) str.Format("%d",i); 浮点数(float) str.Format("%f",i); 字符串指针(char *)等已经被CString构造函数支持的数据类型可以直接赋值 str = username; 五、BSTR、_bstr_t与CComBSTR CComBSTR、_bstr_t是对BSTR的封装,BSTR是指向字符串的32位指针。 char *转换到BSTR可以这样: BSTR b=_com_util::ConvertStringToBSTR("数据"); //使用前需要加上头文件comutil.h 反之可以使用char *p=_com_util::ConvertBSTRToString(b); 六、VARIANT 、_variant_t 与COleVariant VARIANT的结构可以参考头文件VC98\Include\OAIDL.H中关于结构体tagVARIANT的定义。 对于VARIANT变量的赋值:首先给vt成员赋值,指明数据类型,再对联合结构中相同数据类型的变量赋值,举个例子: VARIANT va; int a=2001;

Java中数据类型及其之间的转换

Java中数据类型及其之间的转换 基本的数据类型 基本类型有以下四种: 1)int长度数据类型有:byte(8bits)、short(16bits)、int(32bits)、long(64bits)、2)float长度数据类型有:单精度(32bits float)、双精度(64bits double),JAVA中将小数默认为double类型,若要定义float需在数据后面用f声明; 3)boolean类型变量的取值有:ture、false 4)char数据类型有:unicode字符,16位 对应的类类型:Integer、Float、Boolean、Character、Double、Short、Byte、Long 基本的数据类型由低级到高级分别为:(byte、short、char)——int——long——float——double PS:此处的“级别”是指表示值的范围的大小。 数据类型之间的转转换 分为以下几种情况: 1)低级到高级的自动类型转换; 2)高级到低级的强制类型转换(会导致溢出或丢失精度); 3)基本类型向类类型转换; 4)基本类型向字符串的转换; 5)类类型向字符串转换 基本数据类型之间的转换规则 1.在一个双操作数以及位运算等算术运算式中,会根据操作数的类型将低级的数据类型自动转换为高级的数据类型,分为以下几种情况: 1)只要两个操作数中有一个是double类型的,另一个将会被转换成double类型,并且结果也是double类型; 2)只要两个操作数中有一个是float类型的,另一个将会被转换成float类型,并且结果也是float类型; 3)只要两个操作数中有一个是long类型的,另一个将会被转换成long类型,并且结果也是long类型; 4)两个操作数(包括byte、short、int、char)都将会被转换成int类型,并且结果也是int类型。 2. 如果低级类型为char型,向高级类型(整型)转换时,会转换为对应ASCII码值,再做其它类型的自动转换。 3. 对于byte,short,char三种类型而言,他们是平级的,因此不能相互自动转换,可以使用

相关主题