English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

char A;
float B=1.2;
how can i make char A take the value of 1.2?

i tried A=char(B) in my program....cant work

i also tried float(A)=B.... still wrong...

2006-09-29 05:34:17 · 7 answers · asked by jcol 2 in Computers & Internet Programming & Design

7 answers

there is know way to assign 1.2 to a single char. if you want a sequence of char's to hold a string containing the characters "1.2" you could:

char A[10];
sprintf(A,"%4.1f",B);

2006-09-29 05:38:05 · answer #1 · answered by holden 4 · 1 0

Casting, i.e. A = (char) B should work. Or you could convert it using ftoa. Why would you want to do this in the first place?

2006-09-29 12:37:31 · answer #2 · answered by Anonymous · 0 0

very simple.. lol
use this c library function.

Answer: gcvt(B,2,A)

char * gcvt ( double value, int num, char * buffer );

Parameters.
value
Floating point value to be converted to a string.
num
Number of digits to generate.
buffer
Memory block where to store the resulting string.

2006-09-29 12:47:08 · answer #3 · answered by shivraj s 1 · 0 0

You can't. A character can only hold integer values from -128 to 127 (or from 0 to 255 if it's unsigned).

2006-09-29 12:36:51 · answer #4 · answered by PJ 3 · 0 0

You should probably say what language you're using...

2006-09-29 12:36:07 · answer #5 · answered by Anonymous · 0 0

It will be helpfull if you tell what lang it is?

2006-09-29 12:45:57 · answer #6 · answered by Nestor 4 · 0 0

If C, try sprintf()

2006-09-29 12:36:43 · answer #7 · answered by jrichard377 4 · 0 0

fedest.com, questions and answers