# FormatterBase

> Base class that implements common IFormatter functionality.

## Definition

* **Type:** Class
* **Namespace:** [Unity.SmartStrings.Core.Extensions](/engine/6000.7/script-reference/unity/smartstrings/core/extensions.md)
* **Assembly:** UnityEngine.SmartStringsModule
* **Implements:** [IFormatter](/engine/6000.7/script-reference/unity/smartstrings/core/extensions/iformatter.md)

```csharp
public abstract class FormatterBase : IFormatter
```

## Remarks

This example shows how to create a formatter to format an integer that represents bytes.

## Examples

```csharp
using Unity.SmartStrings.Core.Extensions;

public class ByteFormatter : FormatterBase
{
    public override string DefaultName => "byte";

    public override bool TryEvaluateFormat(IFormattingInfo formattingInfo)
    {
        if (formattingInfo.CurrentValue is long bytes)
        {
            // We are performing a Base 2 conversion here. 1024 bytes = 1 KB
            if (bytes < 512)
            {
                formattingInfo.Write($"{bytes} B");
                return true;
            }

            if (bytes < 512 * 1024)
            {
                var kb = bytes / 1024.0f;
                formattingInfo.Write($"{kb.ToString("0.00")} KB");
                return true;
            }

            bytes /= 1024;
            if (bytes < 512 * 1024)
            {
                var mb = bytes / 1024.0f;
                formattingInfo.Write($"{mb.ToString("0.00")} MB");
                return true;
            }

            bytes /= 1024;
            var gb = bytes / 1024.0f;
            formattingInfo.Write($"{gb.ToString("0.00")} GB");
            return true;
        }

        return false;
    }
}
```

## Constructors

| Constructor                                                                                                 | Description                              |
| ----------------------------------------------------------------------------------------------------------- | ---------------------------------------- |
| [FormatterBase()](/engine/6000.7/script-reference/unity/smartstrings/core/extensions/formatterbase/ctor.md) | Creates a new instance of the formatter. |

## Properties

| Property                                                                                                       | Description                              |
| -------------------------------------------------------------------------------------------------------------- | ---------------------------------------- |
| [DefaultName](/engine/6000.7/script-reference/unity/smartstrings/core/extensions/formatterbase/defaultname.md) | Default name to use when Name is `null`. |
