右截断的浮点变量 [英] right truncate of float variable

查看:50
本文介绍了右截断的浮点变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个浮点变量,如123456789

我想要截断这个并且只显示最多8个最右边的值

所有的时间或以零填充为零它是不到8位数,请

你知道我怎么能显示这个?


谢谢

J.

I have a float variable like 123456789
I want to right truncate this and only display say only 8 right most values
all the time or otherwise filled by zeros if it is less than 8 digits, do
you know how can i display this?

Thanks
J.

推荐答案

在文章< de ********** @ reader01.news.esat.net>中,

Joriveek< no **** @ please.com>写道:
In article <de**********@reader01.news.esat.net>,
Joriveek <no****@please.com> wrote:
我有一个浮动变量,如123456789
我想要截断这个并且只显示只说8个最右边的值
所有的时间或以其他方式用零填充如果它是不到8位,你知道我怎么能显示这个?
I have a float variable like 123456789
I want to right truncate this and only display say only 8 right most values
all the time or otherwise filled by zeros if it is less than 8 digits, do
you know how can i display this?




如果值是(例如)3.1415926535你想做什么?

您只需要显示15926535吗?

-

那时候我还很年轻,但我也很朦胧。 br />
- 克里斯托弗·普里斯特



What do you want done if the value is (e.g.,) 3.1415926535 ?
You would only want the 15926535 displayed?
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest


是的...只有最后10位......


Thanx


" Walter Roberson" < RO ****** @ ibd.nrc-cnrc.gc.ca>在消息中写道

news:de ********** @ canopus.cc.umanitoba.ca ...
yes...only last 10 digits....

Thanx

"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.ca> wrote in message
news:de**********@canopus.cc.umanitoba.ca...
在文章< de ** ********@reader01.news.esat.net>,
Joriveek< no **** @ please.com>写道:
In article <de**********@reader01.news.esat.net>,
Joriveek <no****@please.com> wrote:
我有一个浮点变量,如123456789
我想要截断这个并且只显示最多只说8个值

一直或以其他方式填写如果它小于8位,则为零。确定
你知道如何显示它吗?
I have a float variable like 123456789
I want to right truncate this and only display say only 8 right most
values
all the time or otherwise filled by zeros if it is less than 8 digits, do
you know how can i display this?



如果值是(例如)3.1415926535,你想要做什么?
你只想要显示15926535吗?
-
那时候我很年轻,但我也很朦胧。
- Christopher Priest



What do you want done if the value is (e.g.,) 3.1415926535 ?
You would only want the 15926535 displayed?
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest



在文章< de ********** @ reader01.news.esat.net>,

Joriveek< no****@please.com> top-posted:


[注意:请不要发帖:它会使谈话难以理解]
In article <de**********@reader01.news.esat.net>,
Joriveek <no****@please.com> top-posted:

[Note: please do not top-post: it makes conversations harder to follow]
" Walter Roberson" < RO ****** @ ibd.nrc-cnrc.gc.ca>在消息中写道
新闻:de ********** @ canopus.cc.umanitoba.ca ...
"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.ca> wrote in message
news:de**********@canopus.cc.umanitoba.ca...
在文章< de ****** ****@reader01.news.esat.net>,
Joriveek< no **** @ please.com>写道:
In article <de**********@reader01.news.esat.net>,
Joriveek <no****@please.com> wrote:
我有一个浮点变量,如123456789
我想要截断这个并且只显示最多只说8个值

一直或以其他方式填写如果它小于8位,则按0,你知道我怎么能显示这个?
I have a float variable like 123456789
I want to right truncate this and only display say only 8 right most
values
all the time or otherwise filled by zeros if it is less than 8 digits, do
you know how can i display this?


如果值是(例如),你想做什么?3.1415926535?
你只想要15926535显示?

What do you want done if the value is (e.g.,) 3.1415926535 ?
You would only want the 15926535 displayed?


yes ...只有最后10位....

yes...only last 10 digits....




在原始帖子中,你说8,这次你说10,

恰好是我给的小数点后面的位数

。什么是规则 - 如果小数部分为0,则在

判定点之前的最后8位数,并且小数部分小数点后的前10位数字

为非0 ??


你确实意识到,当你进入更大的价值

如123456789012345时,表示为浮动是

不准确?例如在我碰巧使用的系统上:


(dbx)p(浮动)123456789012345

123456788103168.0


请注意,最后7个地方与原始号码不一致。


除非有什么东西你没告诉我们 - 很好 -

限制浮动的值,然后浮动对于特定内部位置

比数量更重要时表示数字的选择一点都不好。
/>
-

没有人有权通过

要求经验证据来摧毁他人的信念。 - Ann Landers



In your original posting, you said 8, and this time you said 10,
which just happens to be the number of digits after the decimal point
that I gave. What is the "rule" -- the last 8 digits before the
deciminal point if the fractional part is 0, and the first 10 digits
after the decimal point of the fractional part is non-0 ??

You do realize, I hope, that as you get into larger values
such as 123456789012345 that the representation as a float is
inexact? For example on the system I happen to be using:

(dbx) p (float) 123456789012345
123456788103168.0

Notice that the last 7 places do not agree with the original number.

Unless there is something you haven''t told us about that -greatly-
restricts the values of the float, then float is not at all a good
choice for representation of numbers when particular interior positions
are more important than magnitude.
--
"No one has the right to destroy another person''s belief by
demanding empirical evidence." -- Ann Landers


这篇关于右截断的浮点变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆