Feel Like A Number

A couple of things happened recently that make me feel like a piece of meat in the organ grinder of life. First, I was in talks with a publisher about publishing a book with them, and their contract began, “You grant to Us ... the exclusive right to ... sell and otherwise commercially exploit your Work.” I thought, “Well, I guess that’s what work is about, organizations exploiting your work for their commercial profit,” but their writing felt dirty and sleazy, like it was totally controlled by a scumbag lawyer or CEO.

Next, I live in the Terracina apartments in Broomfield, Colorado, and they were recently bought by a new company. With the old company everything here felt like a family, but when the new company bought the place they fired the previous staff, and with most of the new staff it feels like I’m just a number. When I walk in the office the reception feels like, “Number 232 ... you always complain that your kitchen range is vibrating because your downstair’s music is so loud, what do you want? We’re trying to make a lot of money here and you’re a troublemaker.” Twice the office manager has barely looked away from her computer monitor while talking to me.

Both situations remind me of the Bon Seger song, Feel Like a Number.

Scala: How to get the current month as a number or string

Table of Contents1 - Get the current month as an integer number2 - How to get the current month as an abbreviated string3 - How to get the full month name4 - A note about SimpleDateFormat and Locale5 - Summary

Scala FAQ: How do I get the current month as an integer or as a string in Scala?

Scala number, date, and formatting examples

This short blog post contains a collection of Scala number and date examples. I created most of these in the process of writing the Scala Cookbook. Unlike the Cookbook, I don’t describe the examples here much at all, I just show the examples, mostly as a reference for myself (and anyone else that can benefit from them).

Scala numeric types

Scala has these numeric types:

Scala for Java devs: Everything in Scala is an object

The new docs website looks great. It’s also a reminder to me that I probably didn’t stress enough in the Scala Cookbook that everything in Scala is an object, including numbers. (Hopefully I made it clear that functions are objects.) This Scala REPL example shows some of the methods that are available on Scala integers (Int type).

How to compare floating-point numbers in Scala

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 2.5, “Comparing Floating-Point Numbers in Scala.”


You need to compare two floating-point numbers in Scala, but as in some other programming languages, two floating-point numbers that should be equivalent may not be.

How to format numbers and currency in Scala

Scala FAQ: How can I format numbers and currency in Scala, such as to control the number of decimal places and commas in the values, typically for printed output.

Basic formatting

For basic number formatting, use the f string interpolator shown in Recipe 1.4 of the Scala Cookbook, “Substituting Variables into Strings”:

scala> val pi = scala.math.Pi
pi: Double = 3.141592653589793

scala> println(f"$pi%1.5f")

A few more examples demonstrate the technique:

How to use BigInt and BigDecimal when you need very large numbers in Scala

Scala FAQ: I’m writing an application and I need to use very large integer or decimal (floating-point) numbers; what’s the best approach?


Use the Scala BigInt and BigDecimal classes. You can create a BigInt:

scala> var b = BigInt(1234567890)
b: scala.math.BigInt = 1234567890

or a BigDecimal:

Scala: How to parse a number from a String

Scala FAQ: How do I parse a number (Int, Long, Float, etc.) from a String in Scala?


Use the to* methods that are available on a String (courtesy of the Scala StringLike trait):

Ruby command line arguments

Ruby FAQ: How do I read command line arguments in a Ruby script (Ruby command line args)?

To read command line args in a Ruby script, use the special Ruby array ARGV to get the information you need. Here are a few examples.

1) Getting the number of command line args

To get the number of command line arguments passed in to your Ruby script, check ARGV.length, like this: