Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,693 questions

57,001 answers

573 users

How to format currency into millions of dollars in C

2 Answers

0 votes
#include <stdio.h>

void format_millions(double amount, char *out, size_t size) {
    double millions = amount / 1e6;
    
    snprintf(out, size, "$%.2fM", millions);
}

int main() {
    char buf[32] = "";
    
    format_millions(12500000.0, buf, sizeof(buf));
    
    printf("%s\n", buf);   // $12.50M
    
    return 0;
}


/*
run:

$12.50M

*/

 



answered Sep 16 by avibootz
0 votes
#include <stdio.h>

void print_millions(double amount) {
    printf("$%.2fM", amount / 1e6);
}

int main() {
    print_millions(987654321.0);   // $987.65M
    
    return 0;
}


/*
run:

$987.65M

*/

 



answered Sep 16 by avibootz

Related questions

3 answers 359 views
359 views asked Jan 5, 2023 by avibootz
1 answer 334 views
1 answer 339 views
1 answer 287 views
287 views asked Nov 18, 2021 by avibootz
1 answer 348 views
1 answer 235 views
...