How to Display an Int Without Commas

Python : How to format large number without comma

you may use:

print "number : {0:.0f}".format(b)

the zero after dot determines how many decimal digits you want after the the decimal mark. :)

extra:

you don't have to combine strings, just write them as one. It is easier to understand later.

I need to print without comma in last position

You can check the index before printing

n = int(input("Enter a number :-"))
for i in range(1, 11):
end = "," if i < 10 else ""
print(i*n, end = end)

How to get an Excel cell format number without comma when it's an integer and with two digit after comma when it's a float?

There is no such format :-(

As kind of a hack, you could apply a conditional formatting.

As base numberformat use 0,00;-0,00;""

Plus apply the following conditional formatting:

  • Formula: =A1=ROUNDDOWN(A1,0) i.e: = integer
  • Numberformat = 0;-0;""

Convert python string into integer without commas in them

You can do this :

>>> string = '82,000,00'
>>> int(price_result.replace(',', ''))
8200000

PHP number format without comma

See the documentation for number_format: http://php.net/number_format

The functions parameters are:

string number_format ( float $number , int $decimals = 0 , string $dec_point = '.' , string $thousands_sep = ',' )

So use:

number_format(1000.5, 2, '.', '');

Which means that you don't use any (= empty string) thousands separator, only a decimal point.

Convert int array to string without commas in java

int[] arr = new int[]{2, 3, 4, 1, 5};
String res = Arrays.toString(arr).replaceAll("[\\[\\],]", "");
System.out.println(res);

Regular expression for integer with or without commas

You may merge these 2 patterns of yours like

^[+-]?[0-9]+(?:,[0-9]+)*(?:[.][0-9]+)?$

See the regex demo

Details:

  • ^ - start of a string
  • [+-]? - an optional + or -
  • [0-9]+ - 1 or more digits
  • (?:,[0-9]+)* - zero or more sequences of:

    • , - a comma
    • [0-9]+ - 1 or more digits
  • (?:[.][0-9]+)? - an optional sequence of:

    • [.] - a dot
    • [0-9]+ - 1+ digits
  • $ - end of string

A more restrictive regex to only allow 3-digits in groupings will look like

^[+-]?[0-9]{1,3}(?:,[0-9]{3})*(?:[.][0-9]+)?$
^^^^^ ^^^

And if you want to also match whole parts with no thousand separators:

^[+-]?(?:[0-9]{1,3}(?:,[0-9]{3})*|[0-9]+)(?:[.][0-9]+)?$


Related Topics



Leave a reply



Submit