blob: 5c16cc4fc7566dcfb7ff0eb6ccaed9074f5ecb4b [file] [log] [blame]
Haavard Skinnemoenb644d6b2008-08-18 13:41:27 +02001/*
2 * (C) Copyright 2002-2006
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Haavard Skinnemoenb644d6b2008-08-18 13:41:27 +02006 */
7#include <common.h>
8
Ed Swarthoutd065acb2011-03-05 10:28:17 -06009char *strmhz (char *buf, unsigned long hz)
Haavard Skinnemoenb644d6b2008-08-18 13:41:27 +020010{
11 long l, n;
12 long m;
13
Masahiro Yamadaeff8e682014-11-07 03:03:26 +090014 n = DIV_ROUND_CLOSEST(hz, 1000) / 1000L;
Haavard Skinnemoenb644d6b2008-08-18 13:41:27 +020015 l = sprintf (buf, "%ld", n);
Wolfgang Denk709e85d2008-10-19 02:35:48 +020016
17 hz -= n * 1000000L;
Masahiro Yamadaeff8e682014-11-07 03:03:26 +090018 m = DIV_ROUND_CLOSEST(hz, 1000L);
Haavard Skinnemoenb644d6b2008-08-18 13:41:27 +020019 if (m != 0)
20 sprintf (buf + l, ".%03ld", m);
21 return (buf);
22}