How to group decimal places as well?

前端 未结 1 661
轻奢々
轻奢々 2021-01-24 15:01

I want to get x = 1,234,567,890.098,765,432,1.

#include 
#include 
#include 
#include 
us         


        
相关标签:
1条回答
  • 2021-01-24 15:38

    Here's an algorithm:

    Create a function that takes the number to convert as its parameter. Convert that number to a string. Scan the string for a decimal point (while being aware of the possibility for non-numeric results like infinity or indefinite). If found, process the remainder of the string, inserting your separator character after every third digit, stopping when you reach the end of the string or a non-digit (for example, an E to designate an exponent). Return this string.

    As an additional exercise, create a version of this function that can be passed to cout as a manipulator.

    0 讨论(0)
提交回复
热议问题