0

I have function ticketVipCounter to calculate prices

int ticketVipCounter( int ticketVip ){
    return ticketVip * 250000;
}

printf("Prices Is: %d", ticketVipCounter(4));

If i run the code, The result will be 1000000 How do i change the code so the result will be 1.000.000, any idea?, Thankyou

Nico A.L
  • 25
  • 1
  • 8

1 Answers1

1

See this similar question:

How to format a number from 1123456789 to 1,123,456,789 in C?

It looks like if your printf supports POSIX 2008, you can set a locale and use the ' flag.

#include <stdio.h>
#include <locale.h>

int main(void)
{
    setlocale(LC_NUMERIC, "");
    printf("%'d\n", 1123456789);
    return 0;
}
DTynewydd
  • 310
  • 4
  • 10
  • Thankyou, I tried it, but the output is " `d ", I copied all of your code and run it but it still didn't work – Nico A.L Nov 11 '21 at 16:52
  • If you follow the link I posted, the second answer gives a way to implement your own "printfcomma" function which you could adapt to your locale. It could be that your printf doesn't support POSIX 2008, and so doesn't recognise the ```'``` flag – DTynewydd Nov 11 '21 at 16:58
  • Thankyou very much – Nico A.L Nov 12 '21 at 06:15