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