简单的问题,对不起,我可以解决这个问题.我有一些由float(STRING)制作的数字,它们显示为xxx.0,但我希望它们以.00结尾,如果它确实是一个整数.我该怎么做?
谢谢!
编辑:
Python的saiys浮动没有cal'格式()'
我的网站上有一个用户头像.简单图像标签:
<img src="foo.jpg" class="userphoto" width="48" height="48" alt="">
Run Code Online (Sandbox Code Playgroud)
现在,我想在图像左上角的图像上浮动图像(Facebook图标 - 10x10px).
这表示用户已通过Facebook验证.
我怎样才能做到这一点?图像标签上的CSS样式,或者我必须有一个绝对定位的单独div?
不需要透明或任何东西,只需要准确定位在左上角.
当然我不能只是物理修改图像,因为我需要根据Facebook状态确定是否动态覆盖图像.但我希望动态添加一个css类.
有任何想法吗?
回答:
得到它与两个答案的组合工作.使用div而不是另一个图像.
HTML:
<div class="foo">
<div class="fboverlay"></div>
<a>
<img src="foo.jpg" class="userphoto" width="48" height="48" alt="">
</a>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.foo
{
position: absolute;
top: 0;
right: 0;
}
.fboverlay
{
background-image: url('/image/facebook/logo.gif');
position: absolute;
z-index: 1;
top: 10px;
left: 10px;
width: 10px;
height: 10px;
}
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助.
如果我在C/C++中意外编码,下面代码的行为和输出会是什么,
float a = 12.5;
printf("%d\n", a);
printf("%d\n", *(int *)&a);
Run Code Online (Sandbox Code Playgroud) 好的,这就是我的情况:
我有一个核心数据生成类Quantity,它的一个属性'Value',标记为float.
Quantity类中有一个方便的方法,它可以帮助我设置这个属性:
- (void)setValueValue:(float)value_ {
[self setValue:[NSNumber numberWithFloat:value_]];
}
Run Code Online (Sandbox Code Playgroud)
现在,当我设置尝试从这样的控制器设置此值,
Quantity *q = (Quantity *) [NSEntityDescription insertNewObjectForEntityForName:@"Quantity" inManagedObjectContext:self.managedObjectContext];
float qv = 100.0f;
[q setValueValue:qv];
Run Code Online (Sandbox Code Playgroud)
该值设置为1.40129846e-43
我在上面的两个位置都放置了断点,虽然工具提示在Controller类中正确显示值为100.0,但它在setter方法中显示的值不正确.
最终,存储在对象和db中的值是不正确的值.
关于这里发生了什么的任何线索?
将一个浮点数舍入到目标C中最接近1/4的最优雅的方法是什么?
例如:
3.14 should be 3.25
2.72 should be 2.75
6.62 should be 6.50
1.99 should be 2.00
Run Code Online (Sandbox Code Playgroud)
等等
我写了一个小程序来找到点(x,y)相对于由点(px,py)定义的线和与x轴(在笛卡尔坐标系中)的角度(度)相关的位置.
toRadian deg = deg * (pi / 180)
lineSlope deg = tan $ toRadian deg
lineYintercept (x,y) deg = y - (x * lineSlope deg)
relativePointPosition (px,py) deg (x,y)
| s < 0 && deg>=0 && deg<90 = "Left"
| s < 0 && deg>=90 && deg<180 = "Left"
| s < 0 && deg>=180 && deg<270 = "Right"
| s < 0 && deg>=270 && deg<360 = "Right"
| s > 0 && deg>=0 && deg<90 = "Right" …Run Code Online (Sandbox Code Playgroud) 我正在将字符串日期/时间转换为数字时间值.在我的情况下,我只是用它来确定某些东西是否比其他东西更新/更旧,所以这个小小数问题不是一个真正的问题.它不需要秒精确.但它仍然让我挠头,我想知道为什么..
我的日期是@"2010-09-08T17:33:53 + 0000"的字符串格式.所以我写了这个小方法来返回一个时间值.在没有人关心的情况下,如果有人在数月内跳了几天,有28天或31天.在我的数学中,可以假设所有月份都有31天,而且年份有31*12天,因为我不需要两个时间点之间的差异,只知道一个时间点是否晚于另一个时间点.
-(float) uniqueTimeFromCreatedTime: (NSString *)created_time {
float time;
if ([created_time length]>19) {
time = ([[created_time substringWithRange:NSMakeRange(2, 2)]floatValue]-10) * 535680; // max for 12 months is 535680.. uh oh y2100 bug!
time=time + [[created_time substringWithRange:NSMakeRange(5, 2)]floatValue] * 44640; // to make it easy and since it doesn't matter we assume 31 days
time=time + [[created_time substringWithRange:NSMakeRange(8, 2)]floatValue] * 1440;
time=time + [[created_time substringWithRange:NSMakeRange(11, 2)]floatValue] * 60;
time=time + [[created_time substringWithRange:NSMakeRange(14, 2)]floatValue];
time = time + [[created_time substringWithRange:NSMakeRange(17, 2)]floatValue] …Run Code Online (Sandbox Code Playgroud) 我试图重载<运算符,但遇到问题.
这是我的实现:
int Vector3D::operator < (const Vector3D &vector)
{
if(x<vector.x)
return 1;
else
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我用这段代码调用它:
std::map<Vector3D, std::vector<const NeighborTuple *> > position;
std::set<Vector3D> pos;
for (NeighborSet::iterator it = N.begin(); it != N.end(); it++)
{
NeighborTuple const &nb_tuple = *it;
Vector exposition;
pos.insert (exposition);
position[exposition].push_back (&nb_tuple);
}
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
/usr/include/c++/4.1.2/bits/stl_function.h:在成员函数'bool std :: less <_Tp> :: operator()(const _Tp&,const _Tp&)const [with _Tp = ns3 :: Vector3D ]':
/usr/include/c++/4.1.2/bits/stl_map.h:347:从'_Tp&std :: map <_Key,_Tp,_Compare,_Alloc> :: operator [](const _Key&)[与...实例化_Key = ns3 :: Vector3D,_Tp = std …
使用Nunit使用以下代码块测试C#代码:
foreach (XmlNode node in nodeList)
{
thisReport.Id = node.Attributes.GetNamedItem("id").Value;
thisReport.Name = node.Attributes.GetNamedItem("name").Value;
thisReport.Desc = node.Attributes.GetNamedItem("desc").Value;
if (node.SelectNodes("subreport").Count > 0)
{
thisReport.HasSubReport = true;
subReportNodeList = node.SelectNodes("subreport");
foreach(XmlNode subNode in subReportNodeList)
{
mySubReport.ParentID = node.Attributes.GetNamedItem("id").Value;
mySubReport.Priority = subNode.Attributes.GetNamedItem("priority").Value;
mySubReport.SubReportId = subNode.Attributes.GetNamedItem("id").Value;
mySubReport.SubReportName = subNode.Attributes.GetNamedItem("name").Value;
string sTime = subNode.Attributes.GetNamedItem("time").Value;
mySubReport.Time = Convert.ToInt16(sTime);
thisReport.SubReportsList.Add(mySubReport);
}
}
else
{
thisReport.HasSubReport = false;
}
reports.Add(thisReport);
}
Run Code Online (Sandbox Code Playgroud)
代码失败,并在行上使用空对象引用:
thisReport.SubreportsList.Add(mySubReport)
Run Code Online (Sandbox Code Playgroud)
但是查看本地,thisReport存在并且在块的顶部分配了值,并且mySubReport存在并且将值分配在它添加到thisReport的行的正上方.在所有值mySubReport都有效,并且SubReportsList在thisReport是类型的泛型列表SubReport.
那么,null在哪里?看起来很简单,它一定是我看不到的非常明显的东西.
我在我的SQLite中存储一个浮点数(通过核心数据),如下所示:
unit.conversion = [NSNumber numberWithFloat:0.001];
当我查看SQLite数据库时,该值为0.0010000000474974513
unit.conversion是我的datamodel中的可选浮点数...
这有什么问题?
谢谢