How to format timestamp in outgoing JSON

What you can do is, wrap time.Time as your own custom type, and make it implement the Marshaler interface: type Marshaler interface { MarshalJSON() ([]byte, error) } So what you’d do is something like: type JSONTime time.Time func (t JSONTime)MarshalJSON() ([]byte, error) { //do your serializing here stamp := fmt.Sprintf(“\”%s\””, time.Time(t).Format(“Mon Jan _2”)) return []byte(stamp), … Read more

Force point (“.”) as decimal separator in java

Use the overload of String.format which lets you specify the locale: return String.format(Locale.ROOT, “%.2f”, someDouble); If you’re only formatting a number – as you are here – then using NumberFormat would probably be more appropriate. But if you need the rest of the formatting capabilities of String.format, this should work fine.

Formatting Large Numbers with .NET

You can use Log10 to determine the correct break. Something like this could work: double number = 4316000; int mag = (int)(Math.Floor(Math.Log10(number))/3); // Truncates to 6, divides to 2 double divisor = Math.Pow(10, mag*3); double shortNumber = number / divisor; string suffix; switch(mag) { case 0: suffix = string.Empty; break; case 1: suffix = “k”; … Read more