Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/text/format/Formatter#pubctors) \| [Methods](https://developer.android.com/reference/android/text/format/Formatter#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/text/format/Formatter#inhmethods)

# Formatter

*** ** * ** ***


`
public

final

class
Formatter
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.text.format.Formatter |

<br />

*** ** * ** ***

Utility class to aid in formatting common values that are not covered
by the `https://developer.android.com/reference/java/util/Formatter` class in `https://developer.android.com/reference/java/util/package-summary`

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/text/format/Formatter#Formatter()() ` |

| ### Public methods ||
|---|---|
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/text/format/Formatter#formatFileSize(android.content.Context,%20long)(https://developer.android.com/reference/android/content/Context context, long sizeBytes) ` Formats a content size to be in the form of bytes, kilobytes, megabytes, etc. |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/text/format/Formatter#formatIpAddress(int)(int ipv4Address) ` *This method was deprecated in API level 15. Use `https://developer.android.com/reference/java/net/InetAddress#getHostAddress()`, which supports both IPv4 and IPv6 addresses. This method does not support IPv6 addresses.* |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/text/format/Formatter#formatShortFileSize(android.content.Context,%20long)(https://developer.android.com/reference/android/content/Context context, long sizeBytes) ` Like `https://developer.android.com/reference/android/text/format/Formatter#formatFileSize(android.content.Context,%20long)`, but trying to generate shorter numbers (showing fewer digits of precision). |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Public constructors

### Formatter

```
public Formatter ()
```

<br />

<br />

## Public methods

### formatFileSize

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static String formatFileSize (Context context, 
                long sizeBytes)
```

Formats a content size to be in the form of bytes, kilobytes, megabytes, etc.

As of O, the prefixes are used in their standard meanings in the SI system, so kB = 1000
bytes, MB = 1,000,000 bytes, etc.

In `https://developer.android.com/reference/android/os/Build.VERSION_CODES#N` and earlier, powers of 1024 are
used instead, with KB = 1024 bytes, MB = 1,048,576 bytes, etc.

If the context has a right-to-left locale, the returned string is wrapped in bidi
formatting characters to make sure it's displayed correctly if inserted inside a
right-to-left string. (This is useful in cases where the unit strings, like "MB", are
left-to-right, but the locale is right-to-left.)

<br />

<br />

| Parameters ||
|---|---|
| `context` | `Context`: Context to use to load the localized units. This value may be `null`. <br /> |
| `sizeBytes` | `long`: size value to be formatted, in bytes <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | formatted string with the number <br /> |

### formatIpAddress

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
15](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static String formatIpAddress (int ipv4Address)
```


**This method was deprecated
in API level 15.**   

Use `https://developer.android.com/reference/java/net/InetAddress#getHostAddress()`, which supports both IPv4 and
IPv6 addresses. This method does not support IPv6 addresses.

Returns a string in the canonical IPv4 format ###.###.###.### from a packed integer
containing the IP address. The IPv4 address is expected to be in little-endian
format (LSB first). That is, 0x01020304 will return "4.3.2.1".

<br />

| Parameters ||
|---|---|
| `ipv4Address` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |

### formatShortFileSize

Added in [API level 5](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static String formatShortFileSize (Context context, 
                long sizeBytes)
```

Like `https://developer.android.com/reference/android/text/format/Formatter#formatFileSize(android.content.Context,%20long)`, but trying to generate shorter numbers
(showing fewer digits of precision).

<br />

| Parameters ||
|---|---|
| `context` | `Context`: This value may be `null`. <br /> |
| `sizeBytes` | `long` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |