how to convert a float to a string ??

S

sunshinenewton

Hi,

I want to know is there any function in JS the same as "sprintf" in C
language?

Thanks a lot !
 
M

Martin Honnen

I want to know is there any function in JS the same as "sprintf" in C
language?

You can use
number.toString()
to get a string representation or
number.toString(16)
to get a hexadecimal string representation of a number value.
In newer JavaScript implementations there are also further functions such as
numer.toFixed(2)
or
number.toExponential(2)
See the JavaScript documentation here:
<http://developer-test.mozilla.org/docs/Core_JavaScript_1.5_Reference>

<http://developer-test.mozilla.org/docs/Core_JavaScript_1.5_Reference:Objects:Number>
 
T

Thomas 'PointedEars' Lahn

I want to know is there any function in JS the same as "sprintf" in C
language?

This has been asked (for) before, therefore the beginning of an approach
of an ECMAScript compliant s?printf(3) implementation can be found here:

<http://pointedears.de/scripts/string.js>, format()

Comments targeting the script code are welcome.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top