473,324 Members | 2,257 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,324 software developers and data experts.

Automatic type conversions

I know now (thanks to this board) that there are numerous ways to force
a type conversion from a string to a number (such as +, Number(), adding
1, parseInt(), etc).
I'm curious, though...is there any way to force a type conversion the
other way, that is, from a number to a string? Previously, I've just
been assigning numbers to the value property of whatever element I want
to change, which seems to automatically force the appropriate type
conversion (number to string). This seems sloppy though - is there a
way to overtly force this type conversion without having to resort to this?

Thanks,
Aaron
Jul 23 '05 #1
1 1248
On Thu, 01 Apr 2004 13:57:53 -0800, Aaron <ag********@comcast.not> wrote:
I know now (thanks to this board) that there are numerous ways to force
a type conversion from a string to a number (such as +, Number(), adding
1, parseInt(), etc).
I'm curious, though...is there any way to force a type conversion the
other way, that is, from a number to a string? Previously, I've just
been assigning numbers to the value property of whatever element I want
to change, which seems to automatically force the appropriate type
conversion (number to string). This seems sloppy though - is there a
way to overtly force this type conversion without having to resort to
this?


Concatenation with a string:

var str = 6 + '';

or using the String() constructor as a function:

var str = String( 6 );

will convert the number to a plain string. If you want to format the value
as a floating-point number:

<URL:http://jibbering.com/faq/#FAQ4_6>

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #2

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

Similar topics

7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
7
by: bartek | last post by:
Please consider the following scenario below (sketch of). There are two templates defined: A and B, both with mutual conversion operators defined. Also, there's a free function template...
4
by: Jason Heyes | last post by:
I want Foo-type objects to be convertible to Bar-type objects. Can I use operator Bar() to do this just as I would use operator bool() to convert to boolean? Example: class Foo { public:...
8
by: Rade | last post by:
Following a discussion on another thread here... I have tried to understand what is actually standardized in C++ regarding the representing of integers (signed and unsigned) and their conversions....
15
by: buda | last post by:
Let me see if I got this :) 1. I know the rules for type conversions in arithmetic expressions 2. I know that an implicit type conversion is done at assignment, so float x = 1.23; int t = (int)...
3
by: mra | last post by:
I want to cast an object that I have created from a typename to the corresponding type. Can anycone tell me how to do this? Example: //Here, Create the object of type "MyClass" object...
3
by: Szabolcs | last post by:
Consider the attached example. When I try to compile it (with g++ 4.1.2), I get the error message error: no matching function for call to 'fun(A<int>&)' However, if I do not use templates, it...
6
by: Rahul | last post by:
Hi Everyone, I have the following code, class B; class A { public : operator B();
23
by: neha_chhatre | last post by:
which is the best format specifier(data type) if i have to work with decimal number. also please tell me the syntax for truncating a decimal number please reply as soon as possible
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.