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

formatting with int

Hi

I have nos like 10000;

I need to write to a file like
10,000

The "," is inserted.

How could I do this?

Oct 28 '06 #1
5 1433
2005 wrote:
I have nos like 10000;

I need to write to a file like
10,000

The "," is inserted.

How could I do this?
#include <iostream>
#include <locale>
#include <string>

struct my_facet : public std::numpunct<char{
explicit my_facet(size_t refs = 0) : std::numpunct<char>(refs) {}
virtual char do_thousands_sep() const { return ','; }
virtual std::string do_grouping() const { return "\003"; }
};

int main()
{
std::locale global;
std::locale withgroupings(global, new my_facet);
std::locale was = std::cout.imbue(withgroupings);
std::cout << 1000000 << std::endl;
std::cout.imbue(was);
return 0;
}

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 28 '06 #2

Victor Bazarov wrote:
2005 wrote:
I have nos like 10000;

I need to write to a file like
10,000

The "," is inserted.

How could I do this?

#include <iostream>
#include <locale>
#include <string>

struct my_facet : public std::numpunct<char{
explicit my_facet(size_t refs = 0) : std::numpunct<char>(refs) {}
virtual char do_thousands_sep() const { return ','; }
virtual std::string do_grouping() const { return "\003"; }
};

int main()
{
std::locale global;
std::locale withgroupings(global, new my_facet);
std::locale was = std::cout.imbue(withgroupings);
std::cout << 1000000 << std::endl;
std::cout.imbue(was);
return 0;
}
Thanks & seems complicated.

Is it possible to do it any other way - I know that I have about 14
sets of data and most it will have is 6 digits, ie 100,000

Oct 28 '06 #3

Victor Bazarov wrote:
2005 wrote:
I have nos like 10000;

I need to write to a file like
10,000

The "," is inserted.

How could I do this?

#include <iostream>
#include <locale>
#include <string>

struct my_facet : public std::numpunct<char{
explicit my_facet(size_t refs = 0) : std::numpunct<char>(refs) {}
virtual char do_thousands_sep() const { return ','; }
virtual std::string do_grouping() const { return "\003"; }
};

int main()
{
std::locale global;
std::locale withgroupings(global, new my_facet);
std::locale was = std::cout.imbue(withgroupings);
std::cout << 1000000 << std::endl;
std::cout.imbue(was);
return 0;
}
Would it be possible to use get, put or getc, putc etc? If so, how?

Oct 28 '06 #4
2005 wrote:
Victor Bazarov wrote:
>2005 wrote:
>>I have nos like 10000;

I need to write to a file like
10,000

The "," is inserted.

How could I do this?

#include <iostream>
#include <locale>
#include <string>

struct my_facet : public std::numpunct<char{
explicit my_facet(size_t refs = 0) : std::numpunct<char>(refs) {}
virtual char do_thousands_sep() const { return ','; }
virtual std::string do_grouping() const { return "\003"; }
};

int main()
{
std::locale global;
std::locale withgroupings(global, new my_facet);
std::locale was = std::cout.imbue(withgroupings);
std::cout << 1000000 << std::endl;
std::cout.imbue(was);
return 0;
}

Would it be possible to use get, put or getc, putc etc? If so, how?
Write your own function to output a number to a stream with commas
using the % operator:

std::ostream& output_with_commas(std::ostream& os, int number)
{
int last_three_digits = number % 1000;
...
}

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 28 '06 #5

2005 wrote in message
<11**********************@b28g2000cwb.googlegroups .com>...
>
Victor Bazarov wrote:
>2005 wrote:
I have nos like 10000;
I need to write to a file like
10,000
The "," is inserted.
How could I do this?
<snip good example>
>
Thanks & seems complicated.

Is it possible to do it any other way - I know that I have about 14
sets of data and most it will have is 6 digits, ie 100,000
// include <string>, <sstream>, <iostream>, <ostream>
{
int number(123456);
std::ostringstream sos;
sos <<number;
std::string DoComma( sos.str() );
if( DoComma.size() 3 ){
DoComma.insert( DoComma.size()-3, ",");
}
std::cout<<" DoComma ="<<DoComma<<std::endl;
// out: DoComma =123,456
}
--
Bob R
POVrookie
Oct 29 '06 #6

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

Similar topics

3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
2
by: Colleyville Alan | last post by:
I am using Access and have embedded the ActiveX control Formula One that came with Office 2000. (ver 3.04). I have created and formatted a spreadsheet and now I want to copy the info with...
4
by: DBQueen | last post by:
I have a subform which is in Continuous Forms view. I have added a button to the bottom of the page to move to the next record using the button wizard (result: DoCmd.GoToRecord , , acNext). I...
4
by: Bradley | last post by:
I have an A2000 database in which I have a continuous form with a tick box. There is also a text box with a conditional format that is based on the expression , if it's true then change the...
1
by: GGerard | last post by:
Hello Is there a way to use a variable in the Conditional Formatting of a Textbox? Example : I want the background of a textbox in a continuous form to change color when the value of...
4
by: hope | last post by:
Hi, How can I format a string field using Data Formatting Expression property in datagrid? For example: format last name from BROWN to Brown. Thanks
7
by: L. Scott M. | last post by:
Have a quick simple question: dim x as string x = "1234567890" ------------------------------------------------------- VB 6 dim y as string
8
by: gopal | last post by:
Hi I am trying to write to log file but the formatting of string is not properly aligned in log file result The results looks some thing like this OK move.xml Successful OK ...
8
by: Typehigh | last post by:
I have many text fields with conditional formatting applied, specifically when the condition is "Field Has Focus". Without any events associated with the fields the conditional formatting works...
4
by: midlothian | last post by:
Hello, I have conditional formatting set up on a subform based on a calculated value in the underlying query. For instance, if Sales are >$1000, the query displays "Yes," otherwise it displays...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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: 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: 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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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.