# `HL7v2.Type.NM`
[🔗](https://github.com/Balneario-de-Cofrentes/hl7v2/blob/v3.10.1/lib/hl7v2/type/nm.ex#L1)

Numeric (NM) -- HL7v2 primitive data type.

Format: `[+|-]digits[.digits]`. Max 16 characters.

Parses to a `%NM{}` struct that holds both a normalized `value` (for
computation) and the `original` wire string (for lossless round-trip).
`encode/1` emits `original` when present so that parse-then-encode
preserves the exact wire format.  Programmatically-built structs
(where `original` is nil) fall back to emitting `value`.

# `t`

```elixir
@type t() :: %HL7v2.Type.NM{original: binary() | nil, value: binary()}
```

# `encode`

```elixir
@spec encode(t() | binary() | number() | nil) :: binary()
```

Encodes a numeric value back to a string.

For `%NM{}` structs, emits `original` when present (preserving the wire
format), falling back to `value` when `original` is nil (programmatically
built values).

Also accepts plain strings and numbers for backward compatibility.

## Examples

    iex> HL7v2.Type.NM.encode(%HL7v2.Type.NM{value: "1.2", original: "+01.20"})
    "+01.20"

    iex> HL7v2.Type.NM.encode(%HL7v2.Type.NM{value: "42"})
    "42"

    iex> HL7v2.Type.NM.encode("123")
    "123"

    iex> HL7v2.Type.NM.encode(nil)
    ""

# `parse`

```elixir
@spec parse(binary() | nil) :: t() | nil
```

Parses a numeric string into a `%NM{}` struct.

Returns `nil` for empty/nil input. Leading/trailing whitespace is stripped.
The `value` field holds the normalized form (leading zeros, trailing decimal
zeros and bare `+` stripped). The `original` field preserves the raw input
for lossless round-trip encoding.

## Examples

    iex> HL7v2.Type.NM.parse("123")
    %HL7v2.Type.NM{value: "123", original: "123"}

    iex> HL7v2.Type.NM.parse("-45.67")
    %HL7v2.Type.NM{value: "-45.67", original: "-45.67"}

    iex> HL7v2.Type.NM.parse("+01.20")
    %HL7v2.Type.NM{value: "1.2", original: "+01.20"}

    iex> HL7v2.Type.NM.parse("")
    nil

    iex> HL7v2.Type.NM.parse(nil)
    nil

---

*Consult [api-reference.md](api-reference.md) for complete listing*
