• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to pretty print (big)numbers?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to pretty print (big)numbers?


  • Subject: Re: How to pretty print (big)numbers?
  • From: Igor Mozolevsky <email@hidden>
  • Date: Sat, 11 Oct 2014 14:03:02 +0100

On 11 October 2014 13:47, Roland King <email@hidden> wrote:

>
> > On 11 Oct 2014, at 8:22 pm, Igor Mozolevsky <email@hidden>
> wrote:
> >
> > On 11 October 2014 07:03, Gerriet M. Denkmann <email@hidden>
> wrote:
> >
> >> On iOS 8.0:
> >>
> >> UInt64 sum = 16494631536958186120UL;
> >> NSString *sumString =   [ NSNumberFormatter
> >> localizedStringFromNumber:      @(sum)
> >>
> >>      numberStyle:
> NSNumberFormatterDecimalStyle
> >>                                        ];
> >> results in sumString =  -1,952,112,536,751,365,496, which seems not
> quite
> >> right.
> >>
> >
> >
> > Further thought:- Isn't UInt64 a typedef?
> >
> > Try making the ULL (not UL) number with +(NSNumber
> > *)numberWithUnsignedLongLong method of NSNumber…
> >
>
> I already posted that code (in swift) and it doesn’t work, and it’s
> already been explained why NSNumberFormatter doesn’t work on unsigned long
> longs
>


I'm not on -swift list(s) so can you post it here (or to me) for my benefit?


I tried to locale-print the number in plain C, and it works fine (
http://ideone.com/zqnZqg):-

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


int main(void) {
char *numstr;
int out_len;

unsigned long long num = 1649463153695818612;

setlocale(LC_ALL, "");
 const int len = snprintf(NULL, 0, "%'llu", num);
assert(len > 0);

numstr = malloc((size_t) len + 1);
assert(numstr != NULL);
 out_len = snprintf(numstr, len + 1, "%'llu", num);
assert(out_len == len && numstr[len] == 0);
 printf("%s\n", numstr);
 free(numstr);
 return 0;
}

Output:-

Success time: 0 memory: 3996 signal:0

1,649,463,153,695,818,612



--
Igor M.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >How to pretty print (big)numbers? (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: How to pretty print (big)numbers? (From: Igor Mozolevsky <email@hidden>)
 >Re: How to pretty print (big)numbers? (From: Roland King <email@hidden>)

  • Prev by Date: Re: How to pretty print (big)numbers?
  • Next by Date: Re: Concurrent tasks are getting hung up
  • Previous by thread: Re: How to pretty print (big)numbers?
  • Next by thread: How to pretty print floating numbers (without loosing precision)?
  • Index(es):
    • Date
    • Thread