input double but returning a character/string


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: input double but returning a character/string

  1. #1
    Join Date
    Feb 2006
    Posts
    18

    input double but returning a character/string

    Hi everyone,

    I have tried to input a double number from the main and return a character/string using a function but i have not been able to do that as yet. can anyone help me on this?

    Thank you

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    You need to convert the double to a string. The precise implementation details depend on yoru design. You can use stringstream objects to automate the conversion. Otherwise, use sprintf() to convert double to a char array buffer.
    Danny Kalev

  3. #3
    Join Date
    Feb 2006
    Posts
    18
    I am familiar with casting in java but not in C++ .... is it possible to show me a code to convert? i mean if it is some what done like it is done in java.

  4. #4
    Join Date
    May 2006
    Location
    Denmark
    Posts
    39
    you cant cast it, strings are arrays of chars in c/c++.

    so either study sprintf as danny sais or create a function to convert it.

    Depending on what compiler and libraries you use you can look into itoa or IntToStr.

    If you wish to create your own function to convert it, I can give you a hint, to make a single digit a char you can do this: char DigitAsChar = (char)MySingleDigit+'0';
    MySingleDigit beeing a int.

    Then it will add the value of the char '0' to the value of the digit so if the digit = 5 it will be '5' (the char) instaid and the it cast's to a char so it will accept setting a char to the number representation of the character.

    I'm sorry if I over- or under explain.

    GL Thomas.

  5. #5
    Join Date
    Feb 2006
    Posts
    18
    ahhh ok thanks for letting me know about casting.

    i kept trying and before i checked for messages here i made the solution :)

    it was very simple....since i am new i did not know the proper syntax for coding a return function.

    what i have done is i have made a string function. I am sending an integer value and returning a string according to the if statement.

Similar Threads

  1. Need Help With Multi Function Program
    By WackoWolf in forum C++
    Replies: 4
    Last Post: 10-17-2005, 04:22 PM
  2. Replies: 3
    Last Post: 10-02-2005, 11:57 PM
  3. Mortgage calculator help
    By vwrado in forum Java
    Replies: 1
    Last Post: 09-26-2005, 05:09 PM
  4. Beginner: need help
    By Armand in forum Java
    Replies: 2
    Last Post: 08-06-2003, 03:46 AM
  5. Double Text 1.0
    By George Gilbert in forum vb.announcements
    Replies: 0
    Last Post: 08-19-2001, 11:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center