Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
float t=5467453265.457;
int i,d;
i=(int)t;
//itos();
t=t-(int)t;
t*=1000000;
//precision
d=t;
//itos()


What I have tried:

i have tried to read its integer part n decimal part separately but code don't work if int part is greater than range of int
Posted
Updated 24-Mar-16 7:09am
v2
Comments
jeron1 24-Mar-16 11:04am    
Do you need to create a function or can you use an existing one like sprintf()?

link to an sprintf() reference.
http://www.tutorialspoint.com/c_standard_library/c_function_sprintf.htm
Ravinder Singh 24-Mar-16 11:06am    
i need to create
jeron1 24-Mar-16 11:18am    
Try here, I've not tried it myself.
http://www.geeksforgeeks.org/convert-floating-point-number-string/
Richard MacCutchan 24-Mar-16 12:58pm    
Why not just use (s)printf(_s)?
Ravinder Singh 26-Mar-16 2:41am    
because at a point it do system call which i am trying to avoid

1 solution

Check out: Printing Floating-Point Numbers Quickly and Accurately[^] by my friend Robert Burger
 
Share this answer
 
Comments
Ravinder Singh 26-Mar-16 7:57am    
can u plz provide a link for algorithm or program rather than whole theory
Matt T Heffron 28-Mar-16 14:00pm    
Nope.
I'd have to Google it and you can do that as well and can decide which result makes the most sense to you.
I suggest searching:
convert float to string algorithm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900