ioformat

number format

Available under GPL (Free) and Commercial licence
get a GPL licence
COST (GBP)
this unit 1.80
sub units 0.00
add a commercial licence to your cart
0
viewed 7041 times and licensed 125 times
www.codecogs.com/d-ox/io/format/number_format.php
Controller: CodeCogs    Contact Controller

Interface

#include <codecogs/io/format/number_format.h>

using namespace IO::Format;

char* number_format_c (double  value,  int  dp=0,  char  dec_point= '.' ,  char  thousand_sep= ',')
Format a number with grouped thousands.
std::string number_format (double  value,  int  dp=0,  char  dec_point= '.' ,  char  thousand_sep= ',')
Format a number with grouped thousands (memory safe).

Function Documentation

 
char*number_format_cdoublevalue
intdp = 0
chardec_point = '.'
charthousand_sep = ',' )
Format a number, by inserting a separator between every 3 digits of the main number and by rounding the result to the specified number of decimal places. The function is modelled on the PHP equivalent of the same name.

Example:
#include <stdio.h>
#include <codecogs/io/format/number_format.h>
 
int main ()
{
  char* a=IO::Format::number_format_c(234.38645,2);
  printf("\n%s", a);
	delete[](a);
}

Output:
234.39

Warnings:
This function create a dynamic array, ensure you release this memory with delete[]
Parameters:
valueThe number to be converted into a text string.
dpThe number of decimal places to truncate the number to. dp has a range from 0 to 19. (default =0)
dec_pointis the character to be used as a decimal point. (default='.')
thousand_sepCharacter to be inserted after every 3 digits. (default=',')
Returns:
A character string of the formatted number.
Note:
The routine does not work with very very large numbers.
Authors:
Will Bateman (March 2005)
Source Code:
Register

- To get code register with CodeCogs. Already a Member, then Login.


Number Format Calculator

Add calculator to your site or email
 
std::stringnumber_formatdoublevalue
intdp = 0
chardec_point = '.'
charthousand_sep = ',' )
Format a number, by inserting a separator between every 3 digits of the main number and by rounding the result to the specified number of decimal places. The function is modelled on the PHP equivalent of the same name.

This function only differs from that above in that it returns a standard string object, which is automatically released from memory when the object goes out of scrope. Thereby avoiding any possible memory leaks.

Example:
#include <stdio.h>
#include <codecogs/io/format/number_format.h>
 
using namespace IO::Format;
 
int main ()
{
  printf("\n%s", number_format(22.38645,2).c_str());
  printf("\n%s", number_format(122.38245,2).c_str());
  printf("\n%s", number_format(4122.38645,2).c_str());
  printf("\n%s", number_format(-57000000,2,'.',':').c_str());
  printf("\n%s", number_format(-1234.567,2,'.',':').c_str());
  printf("\n%s", number_format(-987.654,2,'.',':').c_str());
}

Output:
22.39
122.38
4,122.39
-57:000:000.00
-1:234.57
-987.65
Parameters:
valueThe number to be converted into a text string.
dpThe number of decimal places to truncate the number to. dp has a range from 0 to 19. (default =0)
dec_pointis the character to be used as a decimal point. (default='.')
thousand_sepCharacter to be inserted after every 3 digits. (default=',')
Returns:
A character string of the formatted number.
Note:
The routine does not work with very very large numbers.
Authors:
Will Bateman (July 2007)
Source Code:
Register

- To get code register with CodeCogs. Already a Member, then Login.


Last Modified: 18 Oct 07 @ 17:07     Page Rendered: 2008-05-14 07:34:51

Page Comments

  You must login to leave a messge


Valid CSS!   Valid XHTML 1.0 Transitional