Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7751835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:38:57+00:00 2026-06-01T11:38:57+00:00

Sample input string: char *str = 12345.567675; And the desired output if I need

  • 0

Sample input string:

char *str = "12345.567675";

And the desired output if I need the precision of 3 places after decimal point:

str = "12345.568";

Is there a way to do this without converting the string to double and back to string?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:38:58+00:00Added an answer on June 1, 2026 at 11:38 am

    yeah, on high level:
    1. search ‘.’ in the string.
    2. if the position of ‘.’ + 3 is smaller than the length you done.
    3. otherwise, concat the string in the position of ‘.’ + 3.
    4. here is tricky: you need to check the next char if exists, (‘.’ + 4), and if it’s value >= 5 goto 4.1 (otherwise goto 5)
    4.1. copy the string to a new string that have one more space on the left (cause 9.9999 will be changed to 10.0000 in the ‘4’ loop) and set a pointer (P) to the last char in that string.
    4.2. if *P between 0 to 8 add 1 to it and go to 5.
    4.3. if *P is 9, set it to zero, move the pointer one left (-1) and goto 4.2
    4.4. if *P is ‘.’, move the pointer one left (-1) and goto 4.2
    5. remove all the 0 on the right of the decimal point (and the decimal point it self if needed) and you done!!!
    6. delete everything, and use the double conversion method…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

package pack; public class sample{ public static void main(String input[]) { NumberFormat numberFormat =
For example Input <url wiki=https://wiki.archlinux.org/index.php/Main_Page forums=https://bbs.archlinux.org/> Desired output <url wiki=https://wiki.archlinux.org/index.php/Main_Page forums=https://bbs.archlinux.org/> Here's a sample
Does it matter if I use a string or char for a simple input
I'm looking for a simple way to tokenize std::string input without using non default
My sample input XML is: <root> <a> <b>item</b> <b>item1</b> <b>item2</b> <b>item3</b> <b>item4</b> </a> </root>
I followed these two exemples of developer.android (Creating an Input Method, Soft Keyboard sample).
I need help with this sample application. When I run it, it gets stuck
I need to parse the below string, and want to use regular expression but
I am trying a reasonably simple program to test binary input/output. I am basically
as per the class reference the TixmlText takes const char* values as input. i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.