import torch


def format_metric(val):
    """Format a tensor/number as a float with 4 digits"""
    if isinstance(val, torch.Tensor):
        val = val.detach().data
    return str('{:.4f}'.format(val))