像int一样浮动(C ++)

时间:2018-07-04 19:16:42

标签: c++

我正在练习使用float并制作了控制台应用程序,该应用程序应该将用户输入的数字加倍。由于某种原因,当我输入1,25之类的数字时,程序输出2(喜欢它的int,而不是float)而不是2 ,5。

代码(我使用Microsoft Visual Studio):

#include "stdafx.h"
#include <iostream>

float racun(float x)
{
    return x * 2;
}

int main()
{
    float y;
    std::cin >> y;
    std::cout << racun(y) << std::endl;
}

预先感谢

1 个答案:

答案 0 :(得分:2)

默认情况下,C ++将使用“美国”十进制表示法,因此<div *ngIf="dataModel" class="container page-content"> <mat-grid-list cols="5"> <mat-grid-tile *ngFor="let page of dataModel.pages" [colspan]="1" [rowspan]="1"> <mat-card > <mat-card-header> <mat-card-title>{{ page.title }}</mat-card-title> </mat-card-header> <img mat-card-image src="{{ this.imageBase + page.id.trim() + '.jpg' }}" alt="Photo of page" /> <mat-card-content> {{ page.matches }} </mat-card-content> <mat-card-actions> <button mat-button routerLink="{{ '/page/' + page.id.trim() }}">VIEW</button> </mat-card-actions> </mat-card> </mat-grid-tile> <mat-grid-tile [colspan]="5"> <button mat-icon-button [disabled]="this.currentIndex == 1" (click)="onNavClick(this.currentIndex - 1)" > <mat-icon aria-label="Previous">navigate_before</mat-icon> </button> <ng-container *ngFor="let item of this.getPageArray(); let i = index;"> <button mat-mini-fab color="primary" (click)="onNavClick(i + 1)">{{ i + 1 }}</button> </ng-container> <button mat-icon-button [disabled]="this.currentIndex == this.dataModel.totalPageResults" (click)="onNavClick(this.currentIndex + 1)"> <mat-icon aria-label="Next">navigate_next</mat-icon> </button> </mat-grid-tile> </mat-grid-list> </div> 被解释为import jenkins.model.* import jenkins.plugins.publish_over_ssh.BapSshHostConfiguration def inst = Jenkins.getInstance() def publishSsh = inst.getDescriptor("jenkins.plugins.publish_over_ssh.BapSshPublisherPlugin") def hostConfigs = publishSsh.getHostConfigurations() return hostConfigs.name // or, if you prefer, return hostConfigs.hostName 而不是1,25

在解析之前,您需要输入1或将1.25转换为1.25