473,395 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how to convert a float to a string ??

Hi,

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

Thanks a lot !

Jul 23 '05 #1
4 30791
<su************@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
I want to know is there any function in JS the same as "sprintf" in C
language?


JS 1.5 has Number.toFixed() and Number.toExponential()
Jul 23 '05 #2


su************@gmail.com wrote:
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>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #3
su************@gmail.com wrote:
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
Jul 23 '05 #4
su************@gmail.com wrote:
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. See

<http://pointedears.de/scripts/test/string>

for a test case.
PointedEars
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function...
4
by: STom | last post by:
How do you convert a string in C# to decimal? STom
15
by: Yifan | last post by:
Hi Does anybody know how to convert System::String* to char*? I searched the System::String class members and did not find any. Thanks Yifan
4
by: Pixie Songbook | last post by:
Hi, I'm trying to write a program using the Dev C++ 4.9.9.2 compiler that takes input numbers from a word document, sums them together, and then gives me a result. It should be easy as the book I...
3
by: priyanka | last post by:
Hi there, I want to convert a String into integer. I get the string from a file using : string argNum; getline(inputStream,argNum); I now need to convert argNum into integer.
1
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does 1+1 equal 11? or How do I convert a string to a number?...
7
by: shellon | last post by:
Hi all: I want to convert the float number to sortable integer, like the function float2rawInt() in java, but I don't know the internal expression of float, appreciate your help!
2
by: lisasahu | last post by:
how to convert float to string like there is atof atoi and itoa but is ther any method to convert float to string
5
by: sidhuasp | last post by:
Hi could anyone please tell me how to convert float value in my database ti HOUR/MIN format for my timesheet requirement. i have to do it in sql-reporting services
3
by: audrey29 | last post by:
How do i convert my string to float?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.