CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2009
    Posts
    30

    Can I parse a double into a char?

    I want to print the value that corresponds to the middle of a string using the Math.ceil() method but I only get it to show the value of the index which is 600. But i want to print the actual character which is an 'A'. How can I do this?

    double center = Math.ceil(FileData.length() / 2);
    System.out.println(center);

  2. #2
    Join Date
    May 2009
    Posts
    2,413

    Re: Can I parse a double into a char?

    Quote Originally Posted by Kl2eativ View Post
    I want to print the value that corresponds to the middle of a string using the Math.ceil() method but I only get it to show the value of the index which is 600. But i want to print the actual character which is an 'A'. How can I do this?

    double center = Math.ceil(FileData.length() / 2);
    System.out.println(center);
    What's the purpose of Math.ceil? In this case it has no effect other than turning an int into a double. This is sufficient (to get the middle String position rounded downwards),

    int center = FileData.length() / 2;

    To get the char corresponding to this String position you can use the charAt() method.

    char centerChar = FileData.charAt(center);
    Last edited by nuzzle; August 3rd, 2011 at 12:22 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
  •  





Click Here to Expand Forum to Full Width

Featured